Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!orion.oac.uci.edu!ucivax!mziober From: mziober@trocadero.ics.uci.edu (Michael A. Ziober) Newsgroups: comp.sys.apple2 Subject: Re: Multitasking on a II Message-ID: <2772A18A.3472@ics.uci.edu> Date: 21 Dec 90 23:58:02 GMT References: <289@generic.UUCP> <1990Dec20.143649.11598@world.std.com> <1990Dec20.184254.16292@nntp-server.caltech.edu> <10739@ucrmath.ucr.edu> Lines: 32 Nntp-Posting-Host: trocadero.ics.uci.edu In <10739@ucrmath.ucr.edu> rhyde@ucrmath.ucr.edu (randy hyde) writes: > If you can come >up with some code to protect a critical region using only INC or DEC as >a test and set instruction I'd be interested in seeing it (I'm not being >facetious, I really don't know if it can be done, although I tend to doubt >it). >*** Randy Hyde Why not? When the resource is initialized by the system: resource_init ... ;blah, blah, blah lda #1 ;could be $ff if you prefer to sta flag ; grab resource with inc ... ;blah, blah, blah Then for each process that wants a piece of the action: your_code ... ;blah, blah, blah loop dec flag ;try to grab resource beq locked ;got it! inc flag ;undo attempt jmp loop ;block until available locked ... ;Here you get exclusive use of the resource. release inc flag ;undo resource lock ... ;blah, blah, blah I think this should work for about 254 processes. With a slight variation on this theme, you can also implement non-blocking resource contention. Michael Ziober