Reader/writer problem.

Reader/writer problem.

Post by Hao H » Sat, 31 May 1997 04:00:00



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

 
 
 

Reader/writer problem.

Post by Mukul Kuma » Wed, 04 Jun 1997 04:00:00


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

2. Routing problems

3. Is this a reader writer problem?

4. PAS16 SCSI CDROM speedup

5. "tee", but with fast writer, 1 slow reader and 1 fast reader

6. Buy me a video card :)

7. pipe() problem - one reader, multiple writers?

8. Package creation

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