Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!caip!sri-spam!nike!ucbcad!ucbvax!nbs-amrf.UUCP!libes From: libes@nbs-amrf.UUCP Newsgroups: mod.computers.vax Subject: Is it possible to do critical regions in VMS? Message-ID: <8608060216.AA06958@seismo.CSS.GOV> Date: Tue, 5-Aug-86 22:16:12 EDT Article-I.D.: seismo.8608060216.AA06958 Posted: Tue Aug 5 22:16:12 1986 Date-Received: Thu, 7-Aug-86 06:15:07 EDT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The ARPA Internet Lines: 56 Approved: info-vax@sri-kl.arpa Is it possible to do critical regions in VMS? I would prefer non-privileged code but, if necessary, some weird privs would be acceptable. My problem is as follows: int x = 0; main() { while (1) { increment(); decrement(); } } increment() {x++;} decrement() {x--;} The user can call subroutines increment and decrement in strictly alternating sequence (as is done here in main()). However, he may ^c or exit (via forcex() or the debugger) at any time. I would like to ensure that x is 0. The reason I can't just set it to 0, is that x is actually shared with several other processes (all doing the same thing). I'm at a loss on how to do this. I'm already using an exit handler, but the exit handler can't tell if it needs to decrement x or not (x actually takes on values > 1, so it can't tell if we've incremented x a different number of times than we've decremented it). No matter how I write it, there is always a window in which I will have a problem. If I could do critical regions in VMS I would like to do something like this: increment() { enter_critical_region(); /* block ^c, ^y, forcex(), etc */ x++; incremented = TRUE; exit_critical_region(); /* ok, now I'm willing to exit */ } exit_handler() { if (incremented) x--; } (In case it's important, I'm using Fortran (patching someone else's code). I'm assuming a language-independent VMS-dependent solution.) I would appreciate it if anyone has a solution to this seemingly simple problem. Thanks. (If anyone knows how to do critical regions in general in VMS, I would like to know, as all the people around here that I asked said that they had run into this problem before to no avail.) Don Libes {seismo,umcp-cs}!nbs-amrf!libes (301) 921-2171