From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Scott McCaskill" To: "Ye Liu" Cc: Subject: Re: critical section Date: Tue, 31 Jul 2001 15:52:00 -0000 Message-id: <019101c11a13$7a067970$3e0f020a@hand.local> References: <3B6722DF.475EAC12@tibco.com> <014d01c11a0f$526d4910$3e0f020a@hand.local> <3B6732F5.2EE3990F@tibco.com> X-SW-Source: 2001/msg00079.html ----- Original Message ----- From: "Ye Liu" To: "Scott McCaskill" Cc: Sent: Tuesday, July 31, 2001 5:36 PM Subject: Re: critical section > In the book of "Programming with POSIX Threads", the author metioned > > "You cannot lock a mutex when the calling thread already has that mutex locked." > > My previous understanding is "a mutex cannot be locked twice", which obviously > is wrong. > > If I use a non-recursive mutex, when a thread try to lock the mutex which is > already locked by another one, what happens to the calling thread? Spin or > yield? > I don't know for sure, but I would expect it to yield. It seems like the spinning that your code is doing would be purely wasteful unless the spinning thread and the mutex-holding thread are on different processors. Can you give us a better idea of what you're trying to accomplish that pthread_mutex won't do for you?