2012-01-11 83 views
0

我遇到的问题是在代码段中的行(1),(2)和(3)。如何在boost中找到当前正在运行的线程?

  1. 如何传递当前正在运行的线程的线程对象?
  2. 如何在不使用boost :: condition_variable的情况下执行上下文切换? (例如:sleep(for ever)
  3. 如何重新运行线程?

1 void wait() 
2 { 
3  if(some condition) 
4  { 
5   queue.enqueue("current thread object"); (1) 
6   boost::this_thread (// context switch) (2) 
7  } 
8 } 
9 
10 void signal() 
11 { 
12  boost::thread myThread = queue.dequeue(); 
13  myThread.run(); (3) 
14 } 

回答

0

虽然我不明白为什么你不只是使用boost::condition_variableboost::thread_pool(取决于你想要做什么)。

有一种叫做boost::context的东西正在审查中,以便加入进来,我认为这是你想要的。

void wait() 
{ 
    if(some condition) 
    { 
     myContext->suspend(); // (2) 
     queue.enqueue(std::move(myContext)); // (1) 
    } 
} 

void signal() 
{ 
     std::unique_ptr<boost::context> myContext = queue.dequeue(); 
     myContext->resume(); // (3) 
} 
:沿线的

东西

相关问题