小编mik*_*o77的帖子

C++:在没有活动异常(GCC)的情况下终止被调用

考虑以下程序:

#include <iostream>
#include <pthread.h>
#include <stdexcept>
#include <unistd.h>

static void* busy(void*)
{
  int oldstate ;
  auto result = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,&oldstate) ;
  if (result != 0)
#ifdef NOEXCEPT
    { std::cerr << "pthread_setcanceltype" << std::endl ; abort() ; }
#else
    throw std::runtime_error("pthread_setcanceltype") ;
#endif
  while (true) 
    ;
  return nullptr ;
}

static pthread_t start()
{
  pthread_t t ;
  int result = pthread_create(&t,nullptr,busy,nullptr) ;
  if (result != 0)
    throw std::runtime_error("pthread_create") ;
  return t ;
}

static void terminate(pthread_t t)
{
  auto result = …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading gcc exception-handling

10
推荐指数
1
解决办法
1533
查看次数

标签 统计

c++ ×1

exception-handling ×1

gcc ×1

multithreading ×1