Question: I'm running a CPU consuming process (calculate mandelbrot set) and that process takes almost 100% of the CPU (I have 8 cores on my machine). when I change the affinity to half of the cores the CPU consumption show 50% or lower and that is cool but what I want to understand is how this magic is done:

**my question:**
If I change the affinity while the process is running and there are threads on disabled cores - Is it safe that I won't lose any data? how is it done?

Answer: 
You have 8 CPU cores, but certainly there are more than 8 threads started. Just count all background processes - there are probably a few dozens of them, each having at least one thread. Operating system must deal with it somehow to provide real multitasking. So OS has a scheduler that starts, pauses and restarts threads according to some algorithm and some set of options. Affinity is one of such options, it determines on which cores the thread can be scheduled. Pausing and restarting threads happens all the time. So does moving them across cores (OS tries to schedule on the same cores, though, because it reduces frequency of cache misses and increases performance). It's safe.
There is absolutely, positively, **no** risk of loss of data (or of data corruption) here. Or of process termination or any other problem. The windows scheduler handles this situation tens or even hundreds of times every second. 

Changing process affinity (or changing its priority for that matter) - which really is changing the affinities (and priorities) of the process's threads - is just another reason for preemption. 

After preemption, a thread may run on a different logical processor than it did the last time it was running. That is a completely common occurrence.