Re: temporary disable thread switching using pthreads
- From: Marcel Müller <news.5.maazl@xxxxxxxxxxxxxxx>
- Date: Tue, 23 May 2006 22:27:55 +0200
davids@xxxxxxxxxxxxx wrote:
On single CPU machines this is much faster than anything else, because
all other threads are obviously not running. There is only a flag for
each process to be set, which prevents the scheduler from scheduling
other threads of the same process. You do not even need a mutex to
protect this flag. No thread is ever descheduled because of the
synchronization. The overhead is nearly zero.
You are basing your conclusions on many assumptions about the specifics
of the implementation. What happens when the one thread that's supposed
to be allowed to run needs a resources that's held by one of the
threads that not allowed to run?
Of course, you must not use a different synchronization mechanisms for the same object. If a resource is protected by a mutex, you must lock the mutex.
In order to actually make this work reliably, you must set a flag that
one thread wants to be exclusive, then wait for every other thread to
acknowledge that it is in a state in which it can safely be suspended.
Right, on multiple CPUs this is most likely a bad choice.
However, getting all the threads to a safe place can be much more
difficult than you might think. For example, suppose thread X gets to a
safe place and suspends, but then thread Y gets into a situation where
it cannot progress until thread X does something, and it holds a
critical resource that the exclusive thread will need.
The latter will not happen, if you do not mix up diffrerent locking mechanisms for the same object.
You have to
backoff, restart all threads, and retry. There is no guarantee you will
ever get all the threads in a safe state.
That's not the way. All depending threads on other CPUs are simply interrupted as if a thread with higher priority is getting ready. That's all. Of course, the current thread have to wait for this to complete.
The point is, this is an incredibly stupid thing to want to do.
The design is from late 80's for IBM PCs. And it was a major improvement over DOS.
There's no good reason to ever do it.
I do not agree. The fact than a solution has a major disadvantage does not necessarily mean that there is no particular case where it is superior.
Marcel
.
- Follow-Ups:
- References:
- temporary disable thread switching using pthreads
- From: Marcel Müller
- Re: temporary disable thread switching using pthreads
- From: David Hopwood
- Re: temporary disable thread switching using pthreads
- From: Marcel Müller
- Re: temporary disable thread switching using pthreads
- From: Joe Seigh
- Re: temporary disable thread switching using pthreads
- From: Marcel Müller
- Re: temporary disable thread switching using pthreads
- From: davids
- temporary disable thread switching using pthreads
- Prev by Date: Re: temporary disable thread switching using pthreads
- Next by Date: Re: temporary disable thread switching using pthreads
- Previous by thread: Re: temporary disable thread switching using pthreads
- Next by thread: Re: temporary disable thread switching using pthreads
- Index(es):
Relevant Pages
|