[clug] Semaphores and shared memory

Jepri jepri at webone.com.au
Wed Dec 10 02:47:28 GMT 2003


Martijn van Oosterhout wrote:

>On Tue, Dec 09, 2003 at 07:18:22PM +1100, Jepri wrote:
>  
>
>>I've got some chunky data files that I would like to access at the same 
>>time from different programs.  I know that I can mmap the files into 
>>different programs at the same time, but what's the right way (TM)  for 
>>the programs to let each other know when they are updating the files?  
>>Ideally I'd use mutex or something, but I'm not sure how to share these 
>>between programs that do not have a common parent.  Do I have to resort 
>>to some kind of formal IPC like SysV shared memory ?
>>    
>>
>
>Mutexes are always between programs, since locking against yourself is
>pretty silly. Semaphores are (IIRC) a generalised version of mutexes in that
>  
>
Unless I fork or start some threads... but that's easy, I just make the 
mutex first.

>man 5 ipc   has some useful info.
>  
>

thx.

>  
>
>>And what are semaphores anyway?  Are they indexes into a kernel 
>>semaphore table or what?
>>    
>>
>
>Basically, yes. Although they're not the same as the ones the kernel uses I
>beleive. And you may want to look into futexes which are like mutexes but
>don't require a trip to the kernel in most cases.
>  
>
This would be a great topic for Brad's SIG programming group.

BTW I'm guessing this would all be very unportable (to windows, also to 
weirder *nixs)?



More information about the linux mailing list