pthread busy wait

Hi all,
On recommendation from a friend, I recently compiled one of my multi-threaded code using busywaiting and it works significantly faster. However, I am not certain i understand how this helps. Has anyone used this option for compiling before ?
Last edited on
It seems it replaces system mutexes and other synchronization objects with something equivalent to this:
while (mutex_is_taken()); //A spinlock, or busy wait.
Normally, the overhead of a mutex is tied to the kernel's scheduler, and how frequently it cycles through the running threads looking for something to give CPU time to. Doing this lowers the overhead to the theoretical minimum, at the cost that waiting threads still use CPU time.
Don't use this if you have threads that are expected to wait for long periods of time (>10 ms or so); for example, threads waiting for I/O results, or threads that just need to sit in the background most of the time and jump in and run a few things from time to time.
Do use this in code that uses lots of synchronization, at it would otherwise spend huge amounts of time waiting for the scheduler to catch up.
Makes sense. I had mostly concluded something similar from what I had read online but wasn't certain. Thanks.
Topic archived. No new replies allowed.