[M3commit] CVS Update: cm3

Randy Coleburn rcoleburn at scires.com
Fri Aug 15 01:46:38 CEST 2008


Jay, this comment is indeed disturbing.  Since, I didn't have anything to do with the Trestle implementation for Windows, I can't really offer an authoritative opinion here.  The phrase "the only reason this *might* work" is especially disturbing as it sounds as if the idea was still being tested and not known to be sound.  
 
I've done quite a bit of multi-threaded programming and the complexity gets out of hand quickly without some rigor and the help of a good thread-aware language like Modula-3.  When I say rigor, I mean the programmers have to set some ground rules that are enforced throughout the code that will ensure correct multi-threaded operation.
 
Arbitrarily releasing locks to prevent potential recursive locks seems like a recipe for disaster and hints that the necessary rigor was not established.
 
Regards,
Randy

>>> Jay <jay.krell at cornell.edu> 8/14/2008 6:05 PM >>>
How about this comment in the code:
 
(*-------------------------------------------------- raw seething windows ---*)
(* NOTE: The helper procedures called by WindowProc lock VBT.mu when calling
   various Trestle procedures.  They do not hold locks while calling Win32
   because it knows nothing about Modula-3 locks and it can, on a whim, call
   WindowProc to do something.  The only reason this scheme might work is
   because we have a single Modula-3 thread that's pulling on the Win32
   message queue and calling WindowProc.
 
   Similarly, we don't bother locking around updates to Child records.
   They are updated by the single Modula-3/WindowProc thread.
*)

?
I also need to check if any state has been modified, or cached in locals, with
the locks held that are being released.
 
 -Jay



Date: Thu, 14 Aug 2008 11:13:25 -0400
From: rcoleburn at scires.com 
To: jkrell at elego.de; m3commit at elegosoft.com 
Subject: Re: [M3commit] CVS Update: cm3


Jay:
 
I haven't studied this code in depth, but on the surface I doubt your change is "correct".  
 
I think the more telling problem is that if you look at the body of WinTrestle.Release, it is empty, save for a comment that it is not yet implemented.  So, it would seem that if WinTrestle.Acquire is called more than once, you will crash because the locks have not been released.
 
Further, I don't think it would make sense to release the locks before calling out to Windows, and then reacquire them upon return.  The locks are known to Modula-3 and not Windows.  Releasing them will allow other competing threads to acquire them while you are in the Windows subsystem and would seem to violate whatever protections were in place per holding the locks.  Upon return from Windows, the thread will be back in competition with others to reacquire the locks it gave up and upon success, there is no guarantee that the other threads didn't disturb the state the original thread depended upon.
 
I would suggest reverting these changes and looking to implement the Release procedure.
 
Regards,
Randy

>>> Jay Krell <jkrell at elego.de> 8/14/2008 4:26 PM >>>
CVSROOT:/usr/cvs
Changes by:jkrell at birch.08/08/14 16:26:59

Modified files:
cm3/m3-ui/ui/src/winvbt/: WinTrestle.m3 

Log message:
release locks when calling out to Win32 to prevent recursive lock acquisition. correct?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3commit/attachments/20080814/cb7c2282/attachment-0002.html>


More information about the M3commit mailing list