这些是用来创build和停止pthread的函数:
void WatchdogController::conscIoUs_process_handler_start() { if ( debug ) cout << "WatchdogController: starting conscIoUs process thread" << endl; cn_pr_thread_active = true; if ( pthread_create( &cn_pr_thread,NULL,conscIoUs_process_handler,this ) < 0 ) { cn_pr_thread_active = false; throw WatchdogException( "Unable to start new thread" ); } } void WatchdogController::conscIoUs_process_handler_stop() { if ( debug ) cout << "WatchdogController: stopping conscIoUs process thread" << endl; cn_pr_thread_active = false; int *retval; pthread_join( cn_pr_thread,( void ** )&retval ); if ( *retval < 0 ) { delete retval; string err = string( "Error returned by conscIoUs_process_handler(): " ) + string( pthread_err ); throw WatchdogException( err.c_str() ); } delete retval; }
我使用传递给pthread的函数中的select(),并在停止时返回一个错误,导致pthread的返回值为负值,但这不是问题,我会稍后解决它 – 问题是,当这个exception抛出:
throw WatchdogException( err.c_str() );
并抓到这里:
AdjustwindowRect文档
修改旧的Windows程序不能在没有源代码访问的情况下通过按键调用exit
在C中运行用户input的外部命令
我怎么知道exit()函数是如何工作的?
如何知道我从哪里启动
try { watchdog_controller->hardware_watchdog_stop(); watchdog_controller->unconscIoUs_process_handler_stop(); watchdog_controller->conscIoUs_process_handler_stop(); } catch ( HardwareWatchdogException &e ) { cerr << "Error stopping hardware watchdog!" << endl; cerr << e.get_reason() << endl; string err = string( "Exception thrown by hardware watchdog controller" ) + string( e.get_reason() ); if ( log ) write_log( err.c_str() ); delete watchdog_controller; return -1; } catch ( WatchdogException &e ) { cerr << "Exception cought when exiting!" << endl; cerr << e.get_reason() << endl; string err = string( "Exception cought when exiting" ) + string( e.get_reason() ); if ( log ) write_log( err.c_str() ); delete watchdog_controller; return -1; }
cerr << e.get_reason() << endl;
可能是什么原因?
参考&e指向的东西,但似乎地址是无效的。
这是exception类:
class WatchdogException { public: /** @brief Default constructor */ WatchdogException() : reason() { } /** @brief Overloaded constructor - setting the error message @param why Error message */ WatchdogException( const char *why ) : reason( why ) { } /** @brief The destructor */ virtual ~WatchdogException() { } /** @brief A getter for the error message @return Returns a string containing error description */ virtual std::string get_reason() const { return reason; } protected: /** @var reason String containing the error message */ std::string reason; };
如何获取$ PATH中的目录作为列表或数组?
延迟加载DLL:应用程序启动多次时,“Exception 0xC06D007E:Module not found”
打印wchar到Linux控制台?
pipe道访问权限setuid程序
从静态库linux C ++中启动一个dynamic库
我猜测你没有正确地为retval分配内存,或者你从cn_pr_thread返回一个无效的指针,这就是为什么当你调用pthread_join时候你会遇到分段错误。
在WatchDogException的构造函数中,你是否记得传入的C字符串的指针,或者是否复制了它。
如果只是存储指针,那么当“err”超出范围时,抛出异常时,c_str()返回的指针将会是坏的,因此当您尝试并使用它时,seg错误。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。