小编Flo*_*inP的帖子

C++ Boost线程睡眠死锁

我有以下代码的问题:

#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <iostream>
#include <sys/types.h>
#include <sys/wait.h>

using namespace std;

void f1(uint count)
{
  while(count-- > 0)
  {
//    boost::this_thread::sleep(boost::posix_time::millisec(1000));
    sleep(1);
  }
}

void folkflore()
{
  int res = fork();
  //parent
  if ( res )
   {
     wait(NULL);
   }
  else
   {
     unsigned int x = 2;
     boost::thread tx(boost::bind(f1, 2));
     tx.join();
     _exit(-5);
   }
}

int main()
{
   std::cout << "Main program " << getpid() << std::endl;
   unsigned int x = 2;
   boost::thread t1(boost::bind(f1, 2));

   boost::thread m(folkflore);
   m.join();
   t1.join(); …
Run Code Online (Sandbox Code Playgroud)

c++ linux multithreading boost fork

6
推荐指数
1
解决办法
1992
查看次数

标签 统计

boost ×1

c++ ×1

fork ×1

linux ×1

multithreading ×1