我有以下代码的问题:
#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)