Module: database-viewer Author: Andy Armstrong, Keith Playford Synopsis: A simple database viewer Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND //// This thread synchronization model lifted wholesale from the environment define variable *thread-count* :: = 0; define constant $thread-lock :: = make(); define constant $final-thread-notification :: = make(, lock: $thread-lock); define method make-application-thread (#rest args, #key function) => () with-lock ($thread-lock) apply(make, , function: application-thread-function(function), args); *thread-count* := *thread-count* + 1; end end method make-application-thread; define method application-thread-function (function :: ) => (new-function :: ) method () block () function() cleanup with-lock ($thread-lock) *thread-count* := *thread-count* - 1; when (*thread-count* = 0) *exit-code* := 0; release($final-thread-notification) end; end; end; end method; end method application-thread-function; define variable *exit-code* :: = 0; define function wait-for-shutdown () => (exit-code :: ) with-lock ($thread-lock) wait-for($final-thread-notification) end; *exit-code* end function wait-for-shutdown;