Exemple #1
0
 void GetCallstack( pthread_t threadId )
 {
   std::lock_guard<std::mutex> lock( callstack_mutex );
   callingThread = pthread_self();
   targetThread = threadId;
   if ( callingThread == targetThread )
   {
     return;
   }
   _setup_callstack_signal_handler();
   // call _callstack_signal_handler in target thread
   if ( pthread_kill( threadId, CALLSTACK_SIG ) != 0 )
   {
     POLLOG_ERROR << "kill failed\n";
     return;
   }
 }
void ExecInThread(ThreadId threadId, boost::function<void(int,void*,void*)> func) {
	
	static Mutex callstackMutex;
	Mutex::ScopedLock lock(callstackMutex);
	
	callingThread = (ThreadId)pthread_self();
	targetThread = threadId;
	threadCallback = func;
	callFinishedSignal = false;
	
	_setup_callstack_signal_handler();

	// call _callstack_signal_handler in target thread
	if(pthread_kill((pthread_t)threadId, CALLSTACK_SIG) != 0) {
		printf("ExecInThread: pthread_kill failed\n");
		return;
	}
	
	while(!callFinishedSignal)
		usleep(100);
	
	threadCallback = NULL;
}