I am a newbie to this forum, and this is actually my first post. I am looking for a way to get the object of the currently running thread in boost. To make this short, consider a case in which one wants to implement a semaphor or a condition variable. That is:

Semaphor:

Queue<boost::thread> queue;

void wait()
{
   if( some condition)
  {
        queue.enqueue( "current thread object" );  (1)
        boost::this_thread ( // context switch )        (2)
  }
}

void signal()
{
     boost::thread myThread = queue.dequeue();
     myThread.run();                                               (3)
}

The problem that I have is with lines (1), (2), and (3) in the snippet.

(1) : how can I pass the thread object of the currently running thread?

(2): how can I perform the context switching without using boost::condition_variable ? (eg. sleep(for ever) )

(3): how can I re-run the thread?

This is easy in Java, but unfortunately I wasn't able to find the solution in boost.

Thank you adatapost, I know that I can use condition variables instead of the queue variable defined in my code, but I am looking for a way to implement a condition variable like 'queue' without using boost::condition variable and boost::mutex. is there any way to have the object of the currently running thread?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.