From: Jackson on
On Nov 20, 1:59 pm, mili <mila...(a)web.de> wrote:
> Hi all,
>
> I am in need of semaphores. I want to synchronize resource access
> between several processes where one process writes and several other
> reads that resource.

I am assuming that you are running several seperate processes and want
to co-ordinate their access to some shared resource rather than having
multiple threads inside a single process.

>
> Is there a semaphore extension already existing? (searched long
> without any success)

I'm not aware of any single extension that does exactly what you want;
however depending on the platform that you are running on these are
the options I am aware of. On Windows the TWAPI package provides
access to the OS Mutex and Semaphore commands (see the Win32 Raw API
documentation). On Unix I'm not aware of any package that wraps the
IPC comamnds (this does not mean that there isn't one) so you may have
to create your own. The issue I always have with Unix IPC is that the
resources don't get cleaned up when a process terminates unexpectedly.
I often use file locking (fcntl) for IPC if simple mutex functionality
is all that is required; file locks get released when the process
holding them terminates.

The other option that you have is to re-engineer the solution so that
the problem goes away: create one or more server processes that are
resposnible for the shared resources and use sockets or the comm
package or some other mechanism to allow the clients to access the
resources. Of course this may not be possible which will bring you
back to sempahores :-)

>
> Thanks,
> Milad