Fcntl () for thread or process synchronization?

Is it possible to use the fcntl () system call on a file to achieve thread / process synchronization (instead of semaphore)?

+3
source share
3 answers

Yes. Unix fcntl locks (and generally the file system resources in general) are system-wide, so any two execution threads (whether they are separate processes or not) can use them. Whether this is a good idea or not depends on the context.

+6
source

, , , , PTHREAD_PROCESS_SHARED POSIX (. pthread_mutexattr_setpshared() pthread_condattr_setpshared()). - IPC ( ..), , , (, select()). , .

, ++, ++-, , boost.interprocess ACE.

+1

fcntl and flock are not for a thread, but for a process, so they cannot be used to synchronize threads.

-1
source

Source: https://habr.com/ru/post/1723383/


All Articles