Thread: Boost.Thread and its synchronization classes

  1. #1
    Ex scientia vera
    Join Date
    Sep 2007

    Boost.Thread and its synchronization classes

    I'm working on a multi-threaded application using Boost.Thread, and I've been wondering about something which I cannot find any concrete information about(due to the ambiguity of the only possible search query).

    Basically, I'm trying to design my application so that it creates N threads, which all have sets of data that needs to be processed. When they finish, they alert my main thread and I give them new data.
    To facilitate this, I'm using an object that contains all the necessary synchronization variables and so on, and this is where I've run into a strange situation that left me wondering.

    The synchronization object looks something like this:

    struct data
        mutex accessSync;
        string myData;
        condition_variable dataReadyCond;
        condition_variable threadDoneCond;
        bool dataReady;
        bool threadDone;
    What I am wondering is why this doesn't seem to be valid(The error is in the mutex and/or condition_variable parts, I know that the other stuff is valid)

    struct data d = {mutex(), "foo", condition_variable(), condition_variable(), false, false};
    The fact that it isn't raises a question: If I create one of the the thread sync objects in question in main, as such:

    mutex m;
    // or
    condition_variable cond;
    They are both valid, fully created objects. What about the struct? I mean, if I create an instance of the struct like I did, are those objects initialized already? If not, why can't I do what I was trying to do above?

    To fix the problem, I used shared_ptrs and allocated them dynamically, but it adds a lot of clutter to the code and I would really like to know if this could be done in this manner, with some modification, or at least know the explanation.

    Thanks in advance!
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    >> What I am wondering is why this doesn't seem to be valid
    What is the error? What compiler?


Popular pages Recent additions subscribe to a feed