CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Feb 2009
    Posts
    326

    boost thread - shared_mutex and condition variable

    Hi,

    1) I would like to know the how I can put an exclusive lock on wait using a condition variable ?

    Given below is my attempt, it contains 4 questions.

    Code:
    #include "boost/thread.hpp"
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        boost :: shared_mutex m1;
        boost :: condition_variable_any c1;
    
        //Do all the 3 locks below behave like scoped_lock (will they get unlocked when they go out of scope) ?
        boost :: shared_lock<boost :: shared_mutex> l1(m1);     //Shared Access
        boost :: upgrade_lock<boost :: shared_mutex> l2(m1);    //2) Is this read lock ? no other thread can read ?
        boost :: upgrade_to_unique_lock<boost :: shared_mutex> l3(l2); //Exclusive Access
    
        c1.wait(l3); //Throws an error, how would I be able to put the l3 on wait ?
                           //3) Also when I do so, what happens to l2, will it also be unlocked when l3 is put on wait ??
                           //4) Can I create l3 without creating l2 ?
    
        //I would like to put l3 on wait, so that what ever lock established is revoked, and when notified it can get the lock back.
        //5) How would I be able to achieve this ?
    
        return(0);
    
    }
    Last edited by Muthuveerappan; April 15th, 2010 at 04:07 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured