Hi, I am trying to implement reader/writer problem using semaphores,
locks, and critical sections. Is there anybody who could give some some
hint ? Thanks.
-Hao
Hi, I am trying to implement reader/writer problem using semaphores,
locks, and critical sections. Is there anybody who could give some some
hint ? Thanks.
-Hao
Yes I can , what is the problem definition ?
Mukul.
> Hi, I am trying to implement reader/writer problem using semaphores,
> locks, and critical sections. Is there anybody who could give some some
> hint ? Thanks.
> -Hao
1. readers-writers problem using SYSV semaphores
To obtain shared-read, exclusive-write and FIFO (assuming the SYSV
semaphore implementation en/dequeues in order), is this algorithm correct?
WRLK = mutex to lock out readers when there is a writer
RDCT = semaphore used to count the number of readers
initially: WRLK=1, RDCT=0
get_shared: | get_exclusive:
Wait(WRLK) | Wait(WRLK)
signal(RDCT) | Sleep till RDCT==0
Signal(WRLK) |
| PROTECTED-REGION
PROTECTED-REGION |
| release_exclusive:
release_shared: | Signal(WRLK)
Wait(RDCT) |
The "Sleep till RCDT==0" is implemented by a semop(2) call with
sem_op=0 on RDCT. Wait() uses sem_op=-1; Signal() uses sem_op=+1.
I have seen an implementation that uses three semaphores and lots of
IPC_NOWAITed semops with sem_op=0, but I didn't understand it.
From my small amount of reading, it seems FIFO queueing of processes
on SYSV semaphores is not guaranteed. Is this correct? If so, this might
explain the extra code in the other implementations that I have seen
that I found to complicated to understand.
-jonathan
--
Jonathan H N Chin, 1 kyu | deputy computer | Newton Institute, Cambridge, UK
"respondeo etsi mutabor" --Rosenstock-Huessy
3. Is this a reader writer problem?
5. "tee", but with fast writer, 1 slow reader and 1 fast reader
7. pipe() problem - one reader, multiple writers?
9. Disk based buffer, one writer, many readers problem
10. reader-writer livelock problem
11. Linux with CDRW (Cd reader/writer) technology?
12. chip-0.2 / driver for MARALU chip-card-reader/writer v1.0
13. ide cdrom and cdrom writer with scsi harddisk using cdrecord can't find cd reader