Re: Locking & Unlocking mechanism in UNIX shared memory
From: Nick Landsberg (hukolau_at_NOSPAM.att.net)
Date: 02/27/04
- Next message: Guillaume Métayer: "Re: Errno.h and EOK constant"
- Previous message: Loic Domaigne: "Re: Locking & Unlocking mechanism in UNIX shared memory"
- In reply to: Loic Domaigne: "Re: Locking & Unlocking mechanism in UNIX shared memory"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 27 Feb 2004 13:00:19 GMT
Loic Domaigne wrote:
> Hi Aravind,
>
>
>>I have a set of processes which work on a shared memory.The shared memory
>>is loaded with the data retrieved from table.I want to know the system
>>calls to lock & unlock a part( say a record) of the shared memory, so
>>that other processes should be allowed to access other records
>>available in the memory when this process locks its memory segment.
>
>
> Your issue doesn't belong to c.p.t, but rather to comp.unix.programmer.
> So I have cross-posted.
>
> A possibility would to use an IPC between your processes in order
> to coordinate the access to the shared memory (Posix or SysV semaphores is
> probably an adequate synchronization device).
>
To add to Loic's suggestion here:
Coordinating multiple writers to shared memory
segments can get very tricky, even with semaphores.
(Many possible race conditions to worry about.)
In my experience a "single writer" design is simplest.
By that I mean that all but one of the processes/threads
are normally free to read any record, but only
one of them can update a record. While the modification
of the record is in progress there may be a need
to prevent readers in order to guarantee that
readers get a consistent record. (Choose your
own semaphore granularity. Anywhere from
semaphore per record to semaphore on the whole
segment. There are arguments for both ways.)
Processes/threads which need to update a record
would send an IPC to the "writer" process/thread
which would perform the actual update.
The IPC is slower, but I have found it to be
safer than mucking around with multiple
(possibly conflicting) writers.
>
> HTH,
> Loic.
-- Ñ "It is impossible to make anything foolproof because fools are so ingenious" - A. Bloch
- Next message: Guillaume Métayer: "Re: Errno.h and EOK constant"
- Previous message: Loic Domaigne: "Re: Locking & Unlocking mechanism in UNIX shared memory"
- In reply to: Loic Domaigne: "Re: Locking & Unlocking mechanism in UNIX shared memory"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|