Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #2277
| From | aminer <aminer@toto.net> |
|---|---|
| Newsgroups | comp.programming.threads, comp.programming |
| Subject | Re: Starvation freedom and the two locks algorithm... |
| Date | 2014-04-27 12:55 -0700 |
| Organization | albasani.net |
| Message-ID | <ljjcqs$3me$5@news.albasani.net> (permalink) |
| References | <ljjbtj$2dm$1@news.albasani.net> |
Cross-posted to 2 groups.
Hello, You have to set the wait parameter of the constructor to "true" and set the option inside the file "defines.inc" to TicketSpinlock or AMLock, so that my concurrent FIFO queue becomes fully starvation-free. Please take a look a=t the source code here: http://pages.videotron.com/aminer/ Thank you, Amine Moulay Ramdane. On 4/27/2014 12:40 PM, aminer wrote: > > Hello, > > > I have just updated my concurrent FIFO queue that uses > a two locks algorithm, before i was doing something like this > on the push() side: > > == > > function TWQueue.push(tm : long):boolean; > begin > > result:=true; > lock1.enter; > if getlength >= fsize > then > begin > result:=false; > lock1.leave; > exit; > end; > > setObject(head,tm); > head:=(head+1); > lock1.leave; > if fwait then sema.signal; > end; > > == > > But the above pop() method is not starvation-free , when the queue is > full and the "if getlength >= fsize" becomes true , the threads > will loop back a, hence this is not starvation-free, to be fully > starvation-free here is what look my updated pop() method: > > == > function TWQueue.push(tm : long):boolean; > begin > > result:=true; > lock1.enter; > if getlength >= fsize > then > begin > while getlength >= fsize > do sleep(0); > end; > > setObject(head,tm); > head:=(head+1); > lock1.leave; > if fwait then sema.signal; > end; > > === > > > When the a thread enters and the "if getlength >= fsize" is > true it will spin-wait inside the locked region until > "if getlength >= fsize" is false, and when you set > the wait parameter to true my concurrent FIFO queue will become > fully starvation-free on both the push() side and on the pop() side. > > > You can download my updated concurrent FIFO queue version 1.02 that uses > the two locks algorithm from: > > http://pages.videotron.com/aminer/ > > > > Thank you, > Amine Moulay Ramdane. > algorithm > > > >
Back to comp.programming.threads | Previous | Next — Previous in thread | Find similar | Unroll thread
Starvation freedom and the two locks algorithm... aminer <aminer@toto.net> - 2014-04-27 12:40 -0700 Re: Starvation freedom and the two locks algorithm... aminer <aminer@toto.net> - 2014-04-27 12:51 -0700 Re: Starvation freedom and the two locks algorithm... aminer <aminer@toto.net> - 2014-04-27 12:55 -0700
csiph-web