Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site ucbvax.BERKELEY.EDU Path: utzoo!decvax!ucbvax!MISTAH.DEC.COM!waters From: waters@MISTAH.DEC.COM (Greg Waters, 225-4986, HLO2-1/J12) Newsgroups: mod.computers.vax Subject: Re: Critical Regions in VAX/VMS Message-ID: <8608111400.AA29739@decwrl.DEC.COM> Date: Mon, 11-Aug-86 09:37:19 EDT Article-I.D.: decwrl.8608111400.AA29739 Posted: Mon Aug 11 09:37:19 1986 Date-Received: Tue, 12-Aug-86 02:31:00 EDT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The ARPA Internet Lines: 53 Approved: info-vax@sri-kl.arpa The original requestor asked how to increment a shared variable at some point in a program, but be able to have an exit handler know whether or not the increment instruction was performed yet. One way to do this is to have the exit handler check where the program was interrupted (compare the saved PC to the critical region). Someone suggested using VMS Locks, which are used to synchronize critical regions of several processes. The poster forgot to mention that the lock would have to be applied between multiple threads of a single process in this application, as in clear go_to_exit_handler lock the counter increment the counter unlock the counter if go_to_exit_handler then goto exit handler and in the exception handler test the counter lock if locked, then dismiss the exception and continue (don't know whether increment is done or not) after setting go_to_exit_handler (so that we regain control later) go to exit handler exit handler if counter has been incremented then decrement it A much more efficient way to create an atomic increment-and-remember-that-I-did operation is to use IPL synchronization. In the main program, replace the increment with status = call sys$cmkrnl( increment_and_remember, %REF(counter), %REF(flag) ) status = call sys$cmkrnl( decrement_and_forget, %REF(counter...)) increment_and_remember: save IPL elevate to IPL$_ASTDEL increment counter set flag restore IPL Now, an asynchronous thread such as the condition handler can accurately determine if the increment has been performed yet or not. IPL$_ASTDEL prevents any asynchronous happenings in the process, such as ^Y or even process deletion requested by some other privileged process. To support multiprocessor VAXes, use ADAWI for the increment, or access the counter through an inter-processor synchronization mechanism (such as an interlocked queue) before altering it. Greg W., DEC Hudson waters%oracle.DEC@decwrl.DEC.COM ...decwrl!dec-rhea!dec-oracle!waters