I'm writing a multi-threaded application that using pthread. It has multiple threads (more than I have cores) to handle several connections and data processing. I would like to organize the threads so that there are 3 cores (out of 4) dedicated to 3 critical tasks, while all other non-critical tasks are in one core. What I am worried about is if the 3 dedicated cores will be slowed down by the thrashing that takes place on the non-critical core. How can I set this up? At first I thought that if I pthread_create() and in that thread pthread_create() all my non-critical threads this would accomplish my goal but I can't find proof of that anywhere. Thanks!
Asked
Active
Viewed 161 times
0
-
WOuld you care to clarify ' At first I thought that if I pthread_create() and in that thread pthread_create() all my non-critical threads this would accomplish my goal'? Also, what platform is this running on? – marko Oct 23 '13 at 21:38
-
3Let the OS do it! Choose the right one! Other hints: [OpenMP](http://openmp.org/wp/) – πάντα ῥεῖ Oct 23 '13 at 21:39
-
2The OS scheduler is smarter than you in that respect, just because it also knows about every other thread in every other process. Let it do its job. CPU affinity is not the right solution for your problem IMHO, using adequate thread priorities is. Also, remember that there are already hundreds or thousands of threads running on your machine, so your concern about "trashing" (I assume you mean cache trashing?) is pretty moot. – syam Oct 23 '13 at 21:41
-
What is your problem exactly? If you want to set the core affinity for each thread, check out http://stackoverflow.com/questions/1407786/how-to-set-cpu-affinity-of-a-particular-pthread – Maciej Stachowski Oct 23 '13 at 21:41
-
Core affinity is exactly what I was looking for, I just couldn't find anything on its existence. I will keep @syam advice in mind though, if you could put your posts as answers so I could accept them that would be great. – user2183336 Oct 23 '13 at 23:04