Is there a way to use pthreads without a scheduler, so context switch occurs only if a thread explicitly yields, or is blocked on a mutex/cond? If not, is there a way to minimize the scheduling overhead, so that forced context switches will occur as rarely as possible?
The question refers to the Linux gcc/g++ implementation of POSIX threads.
You can use Pth (a.k.a. GNU Portable Threads), a non-preemptive thread library. Configuring it with
--enable-pthreadwill create a plug-in replacement forpthreads. I just built and tested this on my Mac and it works fine for a simple pthreads program.From the README: