locked
boost timed mutex RRS feed

  • Question

  • Hi All,

          I am using boost timed_mutex in my VC++ application. I want to know whether timed_mutex locked or not? Is there any way?

    code snippet:

    boost::timed_mutex testmutex;

    in thread1()

    {

    ...

    ...//may locked testmutex

    ...

    }

    in thread2()

    {

    .......

    unlock //if locked, then only unlock. How to know whethere testmutex is locked or not?

    ......

    }

    Thanks in advance,

    • Moved by Jesse Jiang Thursday, April 11, 2013 6:07 AM
    Wednesday, April 10, 2013 7:07 AM

Answers

  • There's no way to just "test" a (boost) mutex (or timed_mutex).   The closest is you can "try_lock" it which either locks it (then you know it was previously unlocked) or failse (in which case it was already locked).   Further, you should NOT unlock a mutex in a thread that wasn't the one that locked it.    That is undefined behavior.

    What are you attempting to do?   

    • Marked as answer by coolstuff1 Thursday, April 11, 2013 10:12 AM
    Wednesday, April 10, 2013 11:20 AM

All replies

  • There's no way to just "test" a (boost) mutex (or timed_mutex).   The closest is you can "try_lock" it which either locks it (then you know it was previously unlocked) or failse (in which case it was already locked).   Further, you should NOT unlock a mutex in a thread that wasn't the one that locked it.    That is undefined behavior.

    What are you attempting to do?   

    • Marked as answer by coolstuff1 Thursday, April 11, 2013 10:12 AM
    Wednesday, April 10, 2013 11:20 AM
  • Hello,

    I think your issue should be raised in the Boost Mail List. I believe they will know more information of this issue than us, and I will move this one to off-topic, because this is a third-part library question.

    Thanks for your understanding,

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, April 11, 2013 6:06 AM
  • Thank you Ron.
    Thursday, April 11, 2013 10:13 AM