I'm trying to understand how does multi-core systems work and how to program efficient programs for systems with many cores. I know this is very hard topic but i'm very interested in fastest solutions possible.
First of all, i'm trying to understand how does threading work. It's obvious, that in most cases multithreading can increase the performance dramatically. According to this page, this is how multithreading work:
But why is switching between N threads is faster than just running N threads one by one ? How can threading work on system with only one CPU ?
Next, what is the point or multi-core programming? I assume that the point is to split threads between cores and split tasks between them ? But how can i split 8 threads on 4 CPU's system equally ?
Do i have to use processor affinity (cpu_affinity) to split threads/processes between CPU's ? Can i create 4 threads using pthread_create on system with 4 CPU's to run each thread on each CPU ?
How hyper-threading helps and is it helps at all ? How can we use CPU cache programming for multi-core systems ?
Why is this so hard for big old projects, like MySQL for example, to fully use advantages of many-CPU systems ?
I'm interested in theory of this problem and also in practical solutions/examples/projects/books/articles for Linux systems (using C).
I know this is increasingly important topic and I hopes I'm not only one interested.