Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
BroadcastCommunity.qnx.com will be offline from May 31 6:00pm until June 2 12:00AM for upcoming system upgrades. For more information please go to https://community.qnx.com/sf/discussion/do/listPosts/projects.bazaar/discussion.bazaar.topc28418
Forum Topic - A mutex in shared memory: Page 1 of 4 (4 Items)
   
A mutex in shared memory  
I'm trying to implement a mutex in shared memory but have run into a problem.

My system is QNX 6.3.0 SP3.
A single process creates a file with shm_open( , O_RDWR | O_CREAT, ) under /dev/shmem and maps it as mmap(, PROT_READ | 
PROT_WRITE, MAP_SHARED, ).
Then process initializes a mutex in shared section with PTHREAD_PROCESS_SHARED and sets a boolean in shared section to 
indicate the mutex is initialized.
Then process locks the mutex and terminates on assertion failure afterwards.
When I start the process for the second time the file already exists so the process only opens it with shm_open(, O_RDWR
, ) without ftruncate() and maps into memory.
It detects the flag that the mutex is already created so it does not do anything else to init the mutex.
After that pthread_mutex_trylock() returns EINVAL instead of expected EBUSY and SyncMutexRevive() returns EINVAL too.
Is that the expected behavior? I was sure the mutex should persist even after all the clients terminate until the file 
is unlinked. Otherwise there is not much sense in all those dances around SyncMutexRevive().