- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there support for shared (read) locks in the user-level synchronization API? I'm developing a Linux application where we do our own non-pThread and non-OpenMP mutexes. The four methods __itt_notify_sync_{prepare, cancel, acquired, releasing} appear to support only exclusive (write) locks. Am I missing something?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The __itt_notify_sync_* API calls are not limited to exclusive locks. You should be able to track a shared lock with something like:
AcquireSharedLock(){ __itt_notify_sync_prepare((void *) &sharedLock); //code to acquire the lock goes here //begin critical section //increment counter //end critical section __itt_notify_sync_acquired((void *) &sharedLock); } ReleaseSharedLock(){ //code to release the lock goes here //begin critical section //decrement counter if(counter == 0) __itt_notify_sync_releasing((void *) &sharedLock); //end critical section }
Best,
-Kevin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Kevin, for your reply.
My understanding is that multiple threads can hold a shared lock while reading from a critical section. But as soon as another thread grabs that shared lock in order to write into the critical section, all the reader threads are then blocked from reading the critical section until the writer thread is done writing and releases the lock.
I'm not sure that your solution enables that feature. Don't you need to tell Thread Checker whether you're holding a shared lock for reading or for writing?
Right now our shared locks cause Thread Checker to report false positives because it doesn't know that it's OK for multiple reader threads to enter a critical section while holding a shared lock.
-- Ron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As far as I am aware, it is not possible to acquire a write lock while other threads have read locks. The write thread should block and wait until there are no active read locks on the resource. (At least, this is the way that shared locks work in both the POSIX and Windows threading APIs.)
-Kevin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
-- Ron
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page