Re: temporary disable thread switching using pthreads



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
.



Relevant Pages

  • Re: Explain this about threads
    ... resource available or raised some other kind of event. ... B's time slice would be yielded to the scheduler in hopes that some ... but then something else must unblock. ... Queue x to be printed ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Leveling problem
    ... > scheduler could ... >> creates the time to do the data management block, ... Your resource says Oops, I did ... >>> because than I am leveling by hand and not by Project. ...
    (microsoft.public.project)
  • Re: Scheduling task service with failover
    ... The Task Scheduler resource would actually have to be active on the node ... >> database (registry hive). ... >> the shared job information is stored on the shared disk. ...
    (microsoft.public.windows.server.clustering)
  • Re: Shadow Copies on IA64 bit win 2003 sp1 failover fails
    ... Is the 'task scheduler' service enabled and running on the node where the resource is failing? ... it manually by removing it from the Scheduled Tasks folder. ... The associated error code is stored in the data section. ...
    (microsoft.public.windows.server.clustering)
  • Re: definition of "atomic"
    ... martin griffith wrote: ... You also need atomic instructions to gate access to a resource. ... have a flag that says "resource busy", it is necessary to have a single ... instruction that will set the flag, ...
    (comp.arch.embedded)