Boost logo

Boost Users :

Subject: [Boost-users] passing variables into thread
From: Alexander Carôt (Alexander_Carot_at_[hidden])
Date: 2016-09-02 16:30:35


Hello all,

I have a thrad function like:

void sj::eventTrigger(){
    boost::mutex::scoped_lock lock(eventTriggerMutex);

    while (eventTriggerActive){
        dFC->eventTriggerLock.wait(lock);

        /// do something with pointer-variable
          
    }
}

This function is executed by a eventTriggerLock.notify_all() – call from other objects and when I need to pass certain variables into the thread I have been unsing a global pointer variable.

Now my question:

I wonder if there is a way to get rid of the pointer variable and directly pass variables into the thread such as:

eventTriggerLock.notify_all(data1)

void sj::eventTrigger(int data1){
    boost::mutex::scoped_lock lock(eventTriggerMutex);

    while (eventTriggerActive){
        dFC->eventTriggerLock.wait(lock);

        /// do something with data1
          
    }
}

Any hint welcome – thanks in advance

Alex


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net