Quote:
Originally Posted by
sanzee
Thanks for the above replies guys, but I want a simple dummy example coe in linux for both scenarios. If you can provide it wud a gr8 help.
Beggars can't be choosers.
I'm not sure I would go with the fcntl.h interface, though. IIRC, ownership is based on PIDs, not TIDs, and although POSIX 1003.1d (previously 1003.4) changed that you might still find non-conforming implementations as 1003.1d compliance is optional.
In any other case (such as synchronization between processes) I would definitely go with the file locking API as it gets the most use on _any_ platform and will therefore be the most bug-free of the implementations. The biggest problem with most thread-based file-locking will be race conditions. Look at the
pthread_condwait family of calls (again, IIRC).