<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Sorry, yes, you are right of course! The Modula-3 spec (and the current pthreads-based implementation as also the win32 implementation I expect) do allow a condition variable being mediated by different mutexes. My comment was clouded by my recollection from the pthreads spec that for pthread mutex/cv behavior for other than 1 mutex per cv is undefined. This confusion may have been the source of prior bugs in the pthreads threading implementation, but those bugs are gone now. We support the M3 spec properly.<div><font class="Apple-style-span" color="#0000FF" face="'Gill Sans'"><br></font></div><div><div><div>On 8 Oct 2009, at 10:34, Mika Nystrom wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Why can't you use the same condition variable with different mutexes?<br><br>This is dynamic, up to the M3 programmer, no?<br><br>Tony Hosking writes:<br><blockquote type="cite"><br></blockquote><blockquote type="cite">--Apple-Mail-96--321618545<br></blockquote><blockquote type="cite">Content-Type: text/plain;<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre"> </span>charset=US-ASCII;<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre"> </span>format=flowed;<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre"> </span>delsp=yes<br></blockquote><blockquote type="cite">Content-Transfer-Encoding: 7bit<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">In general, it is OK in M3 to associate multiple conditions with the <br></blockquote><blockquote type="cite">same mutex. But not vice versa.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">On 8 Oct 2009, at 09:32, Jay K wrote:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><blockquote type="cite">condition variables/win32<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">So..one way I think about condition variables<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">is that you want to be woken when someone else<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">leaves the mutex that guards the data that you are dealing with.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">You want to know when another thread modifies the data.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">(If you have a reader/writer lock, you only want to be<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">woken when someone exits a write.)<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Now, if you consider a producer/consumer queue.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">There are two interesting occurences.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Transitions from empty to non-empty<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">and transitions from full to non-full (optionally,<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">if it is fixed size).<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Consumers wait for empty to non-empty.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Consumers signal full to non-full.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Producers wait for full to non-full.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Producers signal non-empty to empty.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">So, in this case, one mutex is likely used with with two condition <br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">variables.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">But, what if we take a simplifying deoptimization and assume that a <br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">condition<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">variable is only ever associated with one mutex?<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Anyone existing that mutex wakes up anyone waiting on any condition <br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">associated with it?<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Like, a condition variable I think becomes stateless and everything is<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">about the mutex?<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">What is the downside?<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Condition variables are allowed to have spurious wakeups.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">This would "just" increase them. Too much?<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">So, therefore, what would be wrong with the following design?<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> a mutex contains an event<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> and a number of waiters, zero or non-zero<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> if a mutex is exiting with a non-zero number of waiters, signal the <br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">event<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">To handle Signal vs. Broadcast<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">method 1:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> the number of waiters might be interlocked<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> the woken would decrement it<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> if it isn't zero, signal the event again<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">method 2:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> the number of waiters is both an integer and a semaphore<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> and the lock exiter raises the semaphore by the the integer<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">method 3:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> it is not an auto-reset event and there is a count<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> and when the count goes to 0, reset the event<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> I think in this case you have to maintain a "wait generation"<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> so that new waiters don't prevent the count from ever hitting 0.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> I think this #3 is what Java might be doing, and is described here:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><a href="http://www.cs.wustl.edu/~schmidt/win32-cv-1.html">http://www.cs.wustl.edu/~schmidt/win32-cv-1.html</a><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> "3.3. The Generation Count Solution"<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">also:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><a href="http://www.cs.wustl.edu/~schmidt/win32-cv-1.html">http://www.cs.wustl.edu/~schmidt/win32-cv-1.html</a><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">3.2. The SetEvent Solution<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Evaluating the SetEvent Solution<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Incorrectness --<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Is that incorrect case really necessarily incorrect?<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">It seems unfair, since first waiter should be first woken, but..?<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Am I missing something? A lot?<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> - Jay<br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">--Apple-Mail-96--321618545<br></blockquote><blockquote type="cite">Content-Type: text/html;<br></blockquote><blockquote type="cite"><span class="Apple-tab-span" style="white-space:pre"> </span>charset=US-ASCII<br></blockquote><blockquote type="cite">Content-Transfer-Encoding: quoted-printable<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><html><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: space; =<br></blockquote><blockquote type="cite">-webkit-line-break: after-white-space; "><div =<br></blockquote><blockquote type="cite">apple-content-edited=3D"true"><span class=3D"Apple-style-span" =<br></blockquote><blockquote type="cite">style=3D"border-collapse: separate; color: rgb(0, 0, 0); font-family: =<br></blockquote><blockquote type="cite">Helvetica; font-size: 12px; font-style: normal; font-variant: normal; =<br></blockquote><blockquote type="cite">font-weight: normal; letter-spacing: normal; line-height: normal; =<br></blockquote><blockquote type="cite">orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; =<br></blockquote><blockquote type="cite">white-space: normal; widows: 2; word-spacing: 0px; =<br></blockquote><blockquote type="cite">-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: =<br></blockquote><blockquote type="cite">0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =<br></blockquote><blockquote type="cite">auto; -webkit-text-stroke-width: 0; "><div style=3D"word-wrap: =<br></blockquote><blockquote type="cite">break-word; -webkit-nbsp-mode: space; -webkit-line-break: =<br></blockquote><blockquote type="cite">after-white-space; "><span class=3D"Apple-style-span" =<br></blockquote><blockquote type="cite">style=3D"border-collapse: separate; -webkit-border-horizontal-spacing: =<br></blockquote><blockquote type="cite">0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); =<br></blockquote><blockquote type="cite">font-family: Helvetica; font-size: 12px; font-style: normal; =<br></blockquote><blockquote type="cite">font-variant: normal; font-weight: normal; letter-spacing: normal; =<br></blockquote><blockquote type="cite">line-height: normal; -webkit-text-decorations-in-effect: none; =<br></blockquote><blockquote type="cite">text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; =<br></blockquote><blockquote type="cite">orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div =<br></blockquote><blockquote type="cite">style=3D"word-wrap: break-word; -webkit-nbsp-mode: space; =<br></blockquote><blockquote type="cite">-webkit-line-break: after-white-space; "><span class=3D"Apple-style-span" =<br></blockquote><blockquote type="cite">style=3D"border-collapse: separate; -webkit-border-horizontal-spacing: =<br></blockquote><blockquote type="cite">0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); =<br></blockquote><blockquote type="cite">font-family: Helvetica; font-size: 12px; font-style: normal; =<br></blockquote><blockquote type="cite">font-variant: normal; font-weight: normal; letter-spacing: normal; =<br></blockquote><blockquote type="cite">line-height: normal; -webkit-text-decorations-in-effect: none; =<br></blockquote><blockquote type="cite">text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; =<br></blockquote><blockquote type="cite">orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span =<br></blockquote><blockquote type="cite">class=3D"Apple-style-span" style=3D"border-collapse: separate; =<br></blockquote><blockquote type="cite">-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: =<br></blockquote><blockquote type="cite">0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; =<br></blockquote><blockquote type="cite">font-style: normal; font-variant: normal; font-weight: normal; =<br></blockquote><blockquote type="cite">letter-spacing: normal; line-height: normal; =<br></blockquote><blockquote type="cite">-webkit-text-decorations-in-effect: none; text-indent: 0px; =<br></blockquote><blockquote type="cite">-webkit-text-size-adjust: auto; text-transform: none; orphans: 2; =<br></blockquote><blockquote type="cite">white-space: normal; widows: 2; word-spacing: 0px; "><span =<br></blockquote><blockquote type="cite">class=3D"Apple-style-span" style=3D"border-collapse: separate; =<br></blockquote><blockquote type="cite">-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: =<br></blockquote><blockquote type="cite">0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; =<br></blockquote><blockquote type="cite">font-style: normal; font-variant: normal; font-weight: normal; =<br></blockquote><blockquote type="cite">letter-spacing: normal; line-height: normal; =<br></blockquote><blockquote type="cite">-webkit-text-decorations-in-effect: none; text-indent: 0px; =<br></blockquote><blockquote type="cite">-webkit-text-size-adjust: auto; text-transform: none; orphans: 2; =<br></blockquote><blockquote type="cite">white-space: normal; widows: 2; word-spacing: 0px; "><span =<br></blockquote><blockquote type="cite">class=3D"Apple-style-span" style=3D"border-collapse: separate; =<br></blockquote><blockquote type="cite">-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: =<br></blockquote><blockquote type="cite">0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; =<br></blockquote><blockquote type="cite">font-style: normal; font-variant: normal; font-weight: normal; =<br></blockquote><blockquote type="cite">letter-spacing: normal; line-height: normal; =<br></blockquote><blockquote type="cite">-webkit-text-decorations-in-effect: none; text-indent: 0px; =<br></blockquote><blockquote type="cite">-webkit-text-size-adjust: auto; text-transform: none; orphans: 2; =<br></blockquote><blockquote type="cite">white-space: normal; widows: 2; word-spacing: 0px; "><span =<br></blockquote><blockquote type="cite">class=3D"Apple-style-span" style=3D"border-collapse: separate; =<br></blockquote><blockquote type="cite">-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: =<br></blockquote><blockquote type="cite">0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; =<br></blockquote><blockquote type="cite">font-style: normal; font-variant: normal; font-weight: normal; =<br></blockquote><blockquote type="cite">letter-spacing: normal; line-height: normal; =<br></blockquote><blockquote type="cite">-webkit-text-decorations-in-effect: none; text-indent: 0px; =<br></blockquote><blockquote type="cite">-webkit-text-size-adjust: auto; text-transform: none; orphans: 2; =<br></blockquote><blockquote type="cite">white-space: normal; widows: 2; word-spacing: 0px; "><span =<br></blockquote><blockquote type="cite">class=3D"Apple-style-span" style=3D"border-collapse: separate; =<br></blockquote><blockquote type="cite">-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: =<br></blockquote><blockquote type="cite">0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; =<br></blockquote><blockquote type="cite">font-style: normal; font-variant: normal; font-weight: normal; =<br></blockquote><blockquote type="cite">letter-spacing: normal; line-height: normal; =<br></blockquote><blockquote type="cite">-webkit-text-decorations-in-effect: none; text-indent: 0px; =<br></blockquote><blockquote type="cite">-webkit-text-size-adjust: auto; text-transform: none; orphans: 2; =<br></blockquote><blockquote type="cite">white-space: normal; widows: 2; word-spacing: 0px; "><span =<br></blockquote><blockquote type="cite">class=3D"Apple-style-span" style=3D"border-collapse: separate; =<br></blockquote><blockquote type="cite">-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: =<br></blockquote><blockquote type="cite">0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; =<br></blockquote><blockquote type="cite">font-style: normal; font-variant: normal; font-weight: normal; =<br></blockquote><blockquote type="cite">letter-spacing: normal; line-height: normal; =<br></blockquote><blockquote type="cite">-webkit-text-decorations-in-effect: none; text-indent: 0px; =<br></blockquote><blockquote type="cite">-webkit-text-size-adjust: auto; text-transform: none; orphans: 2; =<br></blockquote><blockquote type="cite">white-space: normal; widows: 2; word-spacing: 0px; "><span =<br></blockquote><blockquote type="cite">class=3D"Apple-style-span" style=3D"border-collapse: separate; =<br></blockquote><blockquote type="cite">-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: =<br></blockquote><blockquote type="cite">0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; =<br></blockquote><blockquote type="cite">font-style: normal; font-variant: normal; font-weight: normal; =<br></blockquote><blockquote type="cite">letter-spacing: normal; line-height: normal; =<br></blockquote><blockquote type="cite">-webkit-text-decorations-in-effect: none; text-indent: 0px; =<br></blockquote><blockquote type="cite">-webkit-text-size-adjust: auto; text-transform: none; orphans: 2; =<br></blockquote><blockquote type="cite">white-space: normal; widows: 2; word-spacing: 0px; "><div><span =<br></blockquote><blockquote type="cite">class=3D"Apple-style-span" style=3D"font-size: medium;"><font =<br></blockquote><blockquote type="cite">class=3D"Apple-style-span" color=3D"#0000FF" face=3D"'Gill Sans'">In =<br></blockquote><blockquote type="cite">general, it is OK in M3 to associate multiple conditions with the same =<br></blockquote><blockquote type="cite">mutex. But not vice versa.</font></span></div><div><font =<br></blockquote><blockquote type="cite">class=3D"Apple-style-span" color=3D"#0000FF" face=3D"'Gill Sans'"><span =<br></blockquote><blockquote type="cite">class=3D"Apple-style-span" style=3D"font-size: =<br></blockquote><blockquote type="cite">medium;"><br></span></font></div></span></span></span></span></span></span=<br></blockquote><blockquote type="cite"><blockquote type="cite"></span></span></div></span></div></span></div><div><div>On 8 Oct 2009, =<br></blockquote></blockquote><blockquote type="cite">at 09:32, Jay K wrote:</div><br =<br></blockquote><blockquote type="cite">class=3D"Apple-interchange-newline"><blockquote type=3D"cite"><span =<br></blockquote><blockquote type="cite">class=3D"Apple-style-span" style=3D"border-collapse: separate; color: =<br></blockquote><blockquote type="cite">rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: =<br></blockquote><blockquote type="cite">normal; font-variant: normal; font-weight: normal; letter-spacing: =<br></blockquote><blockquote type="cite">normal; line-height: normal; orphans: 2; text-align: auto; text-indent: =<br></blockquote><blockquote type="cite">0px; text-transform: none; white-space: normal; widows: 2; word-spacing: =<br></blockquote><blockquote type="cite">0px; -webkit-border-horizontal-spacing: 0px; =<br></blockquote><blockquote type="cite">-webkit-border-vertical-spacing: 0px; =<br></blockquote><blockquote type="cite">-webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =<br></blockquote><blockquote type="cite">auto; -webkit-text-stroke-width: 0px; "><div class=3D"hmmessage" =<br></blockquote><blockquote type="cite">style=3D"font-size: 10pt; font-family: Verdana; ">condition =<br></blockquote><blockquote type="cite">variables/win32<br> <br><br>So..one way I think about condition =<br></blockquote><blockquote type="cite">variables<br>is that you want to be woken when someone else<br>leaves =<br></blockquote><blockquote type="cite">the mutex that guards the data that you are dealing with.<br>You want to =<br></blockquote><blockquote type="cite">know when another thread modifies the data.<br>(If you have a =<br></blockquote><blockquote type="cite">reader/writer lock, you only want to be<br>woken when someone exits a =<br></blockquote><blockquote type="cite">write.)<br> <br><br>Now, if you consider a producer/consumer =<br></blockquote><blockquote type="cite">queue.<br>There are two interesting occurences.<br>Transitions from =<br></blockquote><blockquote type="cite">empty to non-empty<br>and transitions from full to non-full =<br></blockquote><blockquote type="cite">(optionally,<br>if it is fixed size).<br> <br><br>Consumers wait =<br></blockquote><blockquote type="cite">for empty to non-empty.<br>Consumers signal full to =<br></blockquote><blockquote type="cite">non-full.<br>Producers wait for full to non-full.<br>Producers signal =<br></blockquote><blockquote type="cite">non-empty to empty.<br> <br><br>So, in this case, one mutex is =<br></blockquote><blockquote type="cite">likely used with with two condition =<br></blockquote><blockquote type="cite">variables.<br> <br><br>But, what if we take a simplifying =<br></blockquote><blockquote type="cite">deoptimization and assume that a condition<br>variable is only ever =<br></blockquote><blockquote type="cite">associated with one mutex?<br>Anyone existing that mutex wakes up anyone =<br></blockquote><blockquote type="cite">waiting on any condition associated with it?<br>Like, a condition =<br></blockquote><blockquote type="cite">variable I think becomes stateless and everything is<br>about the =<br></blockquote><blockquote type="cite">mutex?<br> <br> <br>What is the =<br></blockquote><blockquote type="cite">downside?<br> <br><br>Condition variables are allowed to have =<br></blockquote><blockquote type="cite">spurious wakeups.<br>This would "just" increase them. Too =<br></blockquote><blockquote type="cite">much?<br> <br><br>So, therefore, what would be wrong with the =<br></blockquote><blockquote type="cite">following design?<br> a mutex contains an event<span =<br></blockquote><blockquote type="cite">class=3D"Apple-converted-space"> </span><br> and a number of =<br></blockquote><blockquote type="cite">waiters, zero or non-zero<span =<br></blockquote><blockquote type="cite">class=3D"Apple-converted-space"> </span><br> if a mutex is =<br></blockquote><blockquote type="cite">exiting with a non-zero number of waiters, signal the =<br></blockquote><blockquote type="cite">event<br> <br><br>To handle Signal vs. Broadcast<br>method =<br></blockquote><blockquote type="cite">1:<br> the number of waiters might be interlocked<br> the =<br></blockquote><blockquote type="cite">woken would decrement it<br> if it isn't zero, signal the event =<br></blockquote><blockquote type="cite">again<br> <br><br>method 2:<br> the number of waiters is both =<br></blockquote><blockquote type="cite">an integer and a semaphore<br> and the lock exiter raises the =<br></blockquote><blockquote type="cite">semaphore by the the integer<br><br> <br>method 3:<br> it is =<br></blockquote><blockquote type="cite">not an auto-reset event and there is a count<br> and when the =<br></blockquote><blockquote type="cite">count goes to 0, reset the event<br> I think in this case you have =<br></blockquote><blockquote type="cite">to maintain a "wait generation"<span =<br></blockquote><blockquote type="cite">class=3D"Apple-converted-space"> </span><br> so that new =<br></blockquote><blockquote type="cite">waiters don't prevent the count from ever hitting 0.<br> I think =<br></blockquote><blockquote type="cite">this #3 is what Java might be doing, and is described here:<br><a =<br></blockquote><blockquote type="cite">href=3D"<a href="http://www.cs.wustl.edu/~schmidt/win32-cv-1.html">http://www.cs.wustl.edu/~schmidt/win32-cv-1.html</a>"><a href="http://www.cs.wu">http://www.cs.wu</a>=<br></blockquote><blockquote type="cite">stl.edu/~schmidt/win32-cv-1.html</a><br> "3.3. The Generation Count =<br></blockquote><blockquote type="cite">Solution"<br><br> <br>also:<br><a =<br></blockquote><blockquote type="cite">href=3D"<a href="http://www.cs.wustl.edu/~schmidt/win32-cv-1.html">http://www.cs.wustl.edu/~schmidt/win32-cv-1.html</a>"><a href="http://www.cs.wu">http://www.cs.wu</a>=<br></blockquote><blockquote type="cite">stl.edu/~schmidt/win32-cv-1.html</a><br>3.2. The SetEvent =<br></blockquote><blockquote type="cite">Solution<br>Evaluating the SetEvent Solution<br>Incorrectness --<span =<br></blockquote><blockquote type="cite">class=3D"Apple-converted-space"> </span><br> <br><br>Is that =<br></blockquote><blockquote type="cite">incorrect case really necessarily incorrect?<br>It seems unfair, since =<br></blockquote><blockquote type="cite">first waiter should be first woken, but..?<br><br> <br>Am I missing =<br></blockquote><blockquote type="cite">something? A lot?<br> <br><br> - =<br></blockquote><blockquote type="cite">Jay<br></div></span></blockquote></div><br></body></html>=<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">--Apple-Mail-96--321618545--<br></blockquote></div></blockquote></div><br></div></body></html>