Subj : Re: share a exclusive resource between the threads inside the different To : comp.programming.threads From : Gianni Mariani Date : Wed Mar 23 2005 07:31 am Hank wrote: > Hi, > > Is is possible to share a exclusive resource between the threads inside the > different processes? > For example: ( In linux platform with POSIX thread ) > have 3 processes and each contain 3 threads , in other words there are 9 > threads inside the different processes > how these threads can access the resource synchronously? > mutex? semaphore? locking file? or.......... There are System V IPC mechanisms you can use. see: ftok(3), msgctl(2), msgget(2), msgrcv(2), msgsnd(2), semctl(2), semget(2), semop(2), shmat(2), shmctl(2), shmget(2), shmdt(2) These usually involve the kernel in the synchronization. If you're desperate for performance, you can implement your own IPC mechanisms using shared memory. Another mechanism I have used is simple file locking. The added side effect being that if the process dies, the lock is released which may or may not be good, depending on the application. In theory, file locking also works across systems but nfs file locking has always been a source of bugs. See fcntl F_SETLK, F_SETLKW, F_GETLK etc. .