Subj : Re: Answer David Schwartz 's question To : comp.programming.threads From : David Schwartz Date : Tue Apr 05 2005 01:09 pm "David Hopwood" wrote in message news:o1z4e.32961$C12.3726@fe1.news.blueyonder.co.uk... > Oliver Battenfeld wrote: >> David Schwartz wrote: >> >>>>Can't main thread do anything after STOP other threads? >>> >>> Nope. Suppose another thread was in the middle of 'malloc' when you >>>stopped it. >> >> Question then: What happens, if one such thread is preempted "in the >> middle >> of malloc" by the main thread? > > If the main thread needs the malloc lock, it blocks at that point, and the > thread that holds the lock eventually gets rescheduled and releases it. > > (The reply by David Schwartz misunderstood what you meant by "preempt", I > think.) Perhaps. If by "pre-empt" he just means the normal scheduling mechanism, then there's no problem because the thread will run later and nothing any other thread can do will stop it from finishing its call to 'malloc' and releasing the lock. If by "pre-empt" he means the thread is stopped some way by another thread and only that thread can release it, then if that thread calls 'malloc' (which any function might call 'under-the-hood' unbeknownst to you) then we have a fatal deadlock. DS .