0

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.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by NimaJ
0

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.