- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am implementing a function that the thread need to know the state of the mutex(i.e. locked or free). But I find that TBB mutex does NOT provide such a function interface.
There is a function named "bool M::scoped_lock::try_acquire(M&) " providing a similar action but it can acquire the lock on it if the mutex is free. I just wanna know the state of the mutex rather than acquire the lock on the mutex if it's free.
Can someone help me? How can I achieve my goal? Thanks!
Ray
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Ray!
Generally, you can't reasonably check whether a mutex is locked, because of the race between checking the "state" of the mutex and possible locking/unlocking by another thread. Maybe you could just introduce a boolean flag after mutex::lock/unlock() calls and check when necessary. But still "M:try_lock()" seems to be more reliable. Please, provide the details of your situation, maybe there is another solution for your problem?
-Nikita
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page