Newsgroups: comp.programming.threads
From: Joe Seigh <jseigh...@xemaps.com>
Date: Mon, 02 Aug 2004 15:54:28 GMT
Local: Mon, Aug 2 2004 11:54 am
Subject: Re: lock-free read-write locks
Ronald Landheer-Cieslak wrote: This is code I've posted before. The fetch and op functions are simulated > > Joe has mentioned a rw-spinlock that does not suffer from any starvation > I haven't read the article in detail yet (just found it by typing "rw for the purposes of illustration and you use an interlocked implementation to make them atomic. #define EXCL 1 volatile int n; /* next available ticket */ volatile int x; /* exclusive */ int main() { /*-------------------------------------------------------------------*/ w=fa(&n, EXCL); /* request exclusive access */ w=fa(&n, SHRD); /* request shared access */ /*-------------------------------------------------------------------*/ w=fi(&n); /* request (shared) access */ w=fi(&n); /* request (exclusive) access */ return 0; } They're bakery algorithms with FIFO service order. In the first exclusive requests wait for *all* prior accesses to complete. Shared requests just wait for prior exclusive accesses to complete. Number of waiting threads has to be less than the field sizes. The algorithm works even with wrap and carry out from the exclusive access field into the shared access field. The second version is if you just have fetch and increment. The shared requests have to You can optimize this somewhat by using a power of 2 to define the field size and logically Bakery spinlocks may be more efficient than normal spinlocks since they acquire their wait Joe Seigh You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||