Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use pthread_setaffinity_np
    text
    copied!<p>I am working on a performance critical system that has a lot of logging. I am planning to do my major computation in a thread that sticks to one core, and logs in another thread that sticks to another core. How do I achieve that in pthread_setaffinity_np() ?</p> <p>I imagine that my code would look like </p> <pre><code>void log_something(const string&amp; st) { pthread_setaffinity_np(pthread_self(),sizeof(cpuset),&amp;cpuset); //LOG string st; } int main() { while (true) { // do some computation log_something(something) } } </code></pre> <p>My question is, when I call pthread_setaffinity_np() in log_something(), would it do the logging in the cpu I specified, and while doing the logging, return to the while loop of main() and continue the computation? </p> <p>Or it will switch the entire program to that cpu set, and will only return to main method after logging? </p> <p>Thanks! </p> <p>[EDITED] I use logging as an example but my practical problem is more complicated than that. For example, I might have to update a dynamic parameter every minute, and while I am updating the parameter, I still want to continue my computation in the main() method based on the old parameter (i.e. I just can't stop my main computation for parameter updating). Therefore the process of updating the parameters might have to be migrated to another thread that sticks to another core. So I am looking for a generic solution of separating the computation, not just an efficient logger. </p> <p>Sorry for the confusion. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload