home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.parallel
- Path: sparky!uunet!gatech!hubcap!fpst
- From: gottlieb@allan.ultra.nyu.edu (Allan Gottlieb)
- Subject: Re: Wanted: efficient software lock
- In-Reply-To: engler@cs.arizona.edu's message of 14 Dec 92 07:07:45 GMT
- Message-ID: <1992Dec15.134502.7384@hubcap.clemson.edu>
- Sender: fpst@hubcap.clemson.edu (Steve Stevenson)
- Nntp-Posting-Host: allan.ultra.nyu.edu
- Organization: New York University, Ultracomputer project
- References: <1992Dec14.133731.18997@hubcap.clemson.edu>
- Date: 14 Dec 92 11:59:26
- Approved: parallel@hubcap.clemson.edu
- Lines: 39
-
- In article <1992Dec14.133731.18997@hubcap.clemson.edu> engler@cs.arizona.edu (Dawson R. Engler) writes:
-
- I need the algorithm for an efficient software lock that does not use
- atomic instructions (except perhaps assignment). Fairness is unnecessary:
- in the situation I need this for, ~90% of the accesses are by the same
- process, and if the accesses are by someone else, they are allowed to
- have extra overhead.
-
- If anyone can suggest such an algorithm that has worked well for them
- in practice, I would be grateful.
-
- Regards,
- Dawson
- engler@cs.arizona.edu
-
- P.S. An alternative solution would be a lock that is very effective in
- the case of two processes. Since each lock will belong to a
- specific process, there is a natural dichotomy between the owner and
- "everyone else". From this distiction, two logical processes can
- be created ("me" and "them").
-
- I would suggest peterson's algorithm. For two processes it is simply
- Code for process 1 Code for process 2
- ------------------ ------------------
- P1Wants <- TRUE P2Wants <- TRUE
- Turn <- P2 Turn <- P1
- while P2Wants and Turn=P2 while P1Wants and Turn=P1
-
- critical section critical section
-
- P1Wants <- FALSE P2Wants <- FALSE
-
- (the while loops have empty bodies)
-
- For N processes (plus a proof and references) see Hofri's article in
- Operating Systems Review January 90.
-
- Allan Gottlieb
-
-