<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div apple-content-edited="true"><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div>That thread is supposed to process an event queue, taking events from the Trestle threads, calling out to Windows on their behalf, and sending the result back to the waiting Trestle thread. What lock is it holding? Re-entrance is not a Modula-3 concept, for good reason. I think you may be oversimplifying the need for re-entrance.</div></span></span></span></span></span></span></span></span></div></span> </div><br><div><div>On Aug 15, 2008, at 9:12 PM, Jay wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div class="hmmessage" style="font-size: 10pt; font-family: Tahoma; ">My understanding, could be all wrong:<br>The thread is not intended to hold no locks, just not while calling out.<br>The thread obeys the usual Trestle locking rules.<br> I *believe* it is not a special thread, it just happens to be the thread that all gui stuff happens on. I believe other threads can still do some Trestle stuff, just not that result to calls to Windows.<br>It's obvious why this is happening, from the callstack.<br>Less obvious what to do about it.<br> <br>Is reentrance and working on some data while already working on that data on the same thread really always such a terrible thing? If you know where the points you might reenter from are?<br>That is, while data is locked, it can and will likely go through some states in which it is "incoherent", in which it is "in the middle" of being updated. But isn't the incoherence likely to be over short runs of code? Not likely to be at a point where a function is called? Otherwise, it becomes difficult for even the holder of the lock to keep things straight. I mean, you know, data is usually coherent, but must often pass through incoherence between coherent states. I would expect very little code to deal with the incoherence, for the updating code to be as short as possible.<br> <br> - Jay<br><br><hr><br>CC:<span class="Apple-converted-space"> </span><a href="mailto:m3commit@elegosoft.com">m3commit@elegosoft.com</a><br>From:<span class="Apple-converted-space"> </span><a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a><br>To:<span class="Apple-converted-space"> </span><a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a><br>Subject: Re: [M3commit] recursive locking in WinTrestle<br>Date: Fri, 15 Aug 2008 21:03:41 +0100<br><br><br><div><span class="EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><div style="word-wrap: break-word; "><span class="EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><span class="EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><span class="EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><span class="EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><span class="EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><span class="EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><span class="EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><span class="EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><div>Then the question is why that thread, which is intended *not* to hold any locks so it *can* call out to Windows, actually does hold a lock. Sounds like a bug to me. The fix is to figure out where it is acquiring the lock and deduce what should actually be happening.</div></span></span></span></span></span></span></span></span></div></span></div><br><div><div>On Aug 15, 2008, at 8:37 PM, Jay wrote:</div><br class="EC_Apple-interchange-newline"><blockquote><span class="EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><div class="EC_hmmessage" style="font-size: 10pt; font-family: Tahoma; ">The comment is false. It does call out to Windows with lock held.<br> <br> - Jay<br><br><br><hr><br>From:<span class="EC_Apple-converted-space"> </span><a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a><br>To:<span class="EC_Apple-converted-space"> </span><a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a><br>Date: Fri, 15 Aug 2008 12:51:54 +0100<br>CC:<span class="EC_Apple-converted-space"> </span><a href="mailto:m3commit@elegosoft.com">m3commit@elegosoft.com</a><br>Subject: Re: [M3commit] recursive locking in WinTrestle<br><br><br><div><span class="EC_EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><div style="word-wrap: break-word; "><span class="EC_EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><span class="EC_EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><span class="EC_EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><span class="EC_EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><span class="EC_EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><span class="EC_EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><span class="EC_EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><span class="EC_EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><div>Umm, no, we do not need this for pthreads, since the windowing on non-Windows system does not have the problem you describe. I think that a deeper understanding of the WinTrestle code is needed here. From reading the WinTrestle comments, it says that calls out to Windows are performed by a special thread that has no locks held. So, how can a call-back from Windows (presumably within the same thread) manage to be in a state where the thread has locks. It sounds like there may be something broken in the design of WinTrestle, but this is NOT a motivation to complicate the Thread interface. I suggest that effort be focused in WinTrestle rather than making a global hack that is not justified.</div></span></span></span></span></span></span></span></span></div></span></div><br><div><div>On Aug 15, 2008, at 12:29 PM, Jay wrote:</div><br class="EC_EC_Apple-interchange-newline"><blockquote><span class="EC_EC_Apple-style-span" style="word-spacing: 0px; font: normal normal normal 12px/normal Helvetica; text-transform: none; color: rgb(0, 0, 0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; "><div class="EC_EC_hmmessage" style="font-size: 10pt; font-family: Tahoma; ">There is a case, trivial to hit, in WinTrestle that calls out to Windows with some locks held, Windows calls back into Trestle, Trestle attempts to acquire the locks again, and it dies.<br><br>It should be easy to implement...<br><br>All it takes to hit this in WinTrestle is to copy (as in copy/paste) twice in the same app.<br>My example was from the same control but that isn't necessary.<br>Just copy from one Trestle control and then copy from another and it hits.<br><br>A careful review might reveal that is safe to release the locks, call out, reacquire.<br>The comments indicate a general non-calling out with locks held, but the implementation does not quite agree.<br><br>pthread has this: PTHREAD_MUTEX_RECURSIVE<br>It's just bogus?<br><br>One lock type -- nonrecursive mutex -- is really all you need?<br><br>I assume a multi-reader/single-writer is also useful. In fact, a mutex can just be a reader/writer where everyone is a writer, though that might waste space (given that Windows now has a reader/writer lock that is just the size of a pointer, maybe not).<br><br>- Jay<br><br>> From:<span class="EC_EC_Apple-converted-space"> </span><a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a><br>> To:<span class="EC_EC_Apple-converted-space"> </span><a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a><br>> Date: Fri, 15 Aug 2008 11:41:23 +0100<br>> CC:<span class="EC_EC_Apple-converted-space"> </span><a href="mailto:m3commit@elegosoft.com">m3commit@elegosoft.com</a><br>> Subject: Re: [M3commit] CVS Update: cm3<br>><br>> I am unclear as to why this abstraction is needed for Windows threads<br>> when it is not needed for pthreads. Please explain.<br>><br>> On Aug 15, 2008, at 2:08 AM, Jay wrote:<br>><br>> ><br>> > We should probably add a new type Thread.RecursiveExclusiveLock? And<br>> > then just use that here?<br>> > The basic Win32 critical section is such a thing precisely. Not that<br>> > it is all that great. But it is widely used.<br>> > Vista adds the "SRWLock" which is a small read/write lock and maybe<br>> > reduced recursive functionality.<br>> > It is indeed small, just the size of a pointer, whereas a critical<br>> > section is fairly large.<br>> ><br>> > - Jay<br>> ><br>> ><br>> ><br>> > Date: Thu, 14 Aug 2008 20:11:19 -0400From:<span class="EC_EC_Apple-converted-space"> </span><a href="mailto:rcoleburn@scires.comTo">rcoleburn@scires.comTo</a>:<span class="EC_EC_Apple-converted-space"> </span><a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a><br>> > ;<span class="EC_EC_Apple-converted-space"> </span><a href="mailto:jkrell@elego.de">jkrell@elego.de</a>;<span class="EC_EC_Apple-converted-space"> </span><a href="mailto:m3commit@elegosoft.comSubject">m3commit@elegosoft.comSubject</a>: Re: [M3commit] CVS<br>> > Update: cm3<br>> ><br>> > Jay:<br>> ><br>> > There is the abstraction of multiple concurrent "readers" but only<br>> > one "writer". I actually have such a module that I use sometimes in<br>> > my programs. The idea is one of acquiring/releasing read locks and<br>> > write locks. The difficulty here is in preventing starvation and<br>> > usually requires adherence to some rules (again rigor). By<br>> > starvation I mean that writers must wait for all readers to finish<br>> > before they get access, so if there is always at least one reader,<br>> > the writer will "starve" and never gain access.<br>> ><br>> > As for recursive locks, again that is usually indicative of a design<br>> > flaw. I did once implement a system that permitted the same thread<br>> > to acquire a lock multiple times, provided that it eventually<br>> > released the lock the same number of times that it acquired it. In<br>> > other words, after the first lock, subsequent locks by the same<br>> > thread just increment a counter. Then, unlocks decrement the<br>> > counter until it is zero with the final unlock actually releasing<br>> > the mutex.<br>> ><br>> > In the code you modified, you could implement such a scheme to<br>> > handle the recursive locks, provided that at some point the thread<br>> > releases for each lock. The Thread interface has the ability to<br>> > note the current thread (i.e., Thread.Self()). So you could make a<br>> > stack of locks by same thread. Other threads would have to block<br>> > until the first thread's lock stack was empty.<br>> ><br>> > For example:<br>> ><br>> > ACQUIRE: If resource available, lock resource mutex and put current<br>> > thread on granted stack. Otherwise, if current thread already on<br>> > granted stack, push it on stack again and let it proceed. Otherwise<br>> > (this is a new thread wanting access), so push this thread onto a<br>> > waiting stack and wait<br>><br><br></div></span></blockquote></div><br></div></span><br class="EC_Apple-interchange-newline"></blockquote></div><br></div></span><br class="Apple-interchange-newline"></blockquote></div><br></body></html>