小编Hie*_*erg的帖子

C++ gettid()未在此范围内声明

一个简单的程序是:我想使用这个gettid函数获取两个线程的线程ID.我不想直接做sysCall.我想使用这个功能.

#include <iostream>
#include <boost/thread/thread.hpp>
#include <boost/date_time/date.hpp>
#include <unistd.h>
#include <sys/types.h>
using namespace boost;
using namespace std;

boost::thread thread_obj;
boost::thread thread_obj1;

void func(void)
{
    char x;
    cout << "enter y to interrupt" << endl;
    cin >> x;
     pid_t tid = gettid();
    cout << "tid:" << tid << endl;
    if (x == 'y') {
        cout << "x = 'y'" << endl;    
        cout << "thread interrupt" << endl;
    }
}

void real_main() {

   cout << "real main thread" << endl;
    pid_t tid …
Run Code Online (Sandbox Code Playgroud)

system-calls boost-thread linux-kernel c++11

12
推荐指数
3
解决办法
1万
查看次数

如何使boost/asio库重复计时器?

以下是Boost库文档中给出的代码.

#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

void print(const boost::system::error_code& /*e*/)
{
  std::cout << "Hello, world!\n";
}

int main()
{
  boost::asio::io_service io;

  boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
  t.async_wait(print);

  io.run();

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

现在当我运行上面的程序时,它只等待5秒然后打印Hello World并停止.我希望这个程序每5秒钟继续打印Hello World.可能吗 ?

c++ boost boost-thread boost-asio

3
推荐指数
1
解决办法
3610
查看次数