我尝试在一个单独的线程中启动一个有限状态机:
int main(int argc, char *argv[])
{
uint8_t payload[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
MessageA* message_temp = new MessageA(0x0F, payload); //MessageA derives from Message
std::vector<Message*> outBuffer;
pthread_t t1;
int rc;
rc = pthread_create(&t1, NULL, createFsmThread,pParam);
rc = pthread_join(t1,NULL);
/* Perform some operations */
for(i = 0; i < 5; i++)
{
outBuffer.push_back(message_temp);
}
return EXIT_SUCCESS;
}
void *createFsmThread(void* lpParam)
{
std::cout << "Start the FSM Threat for Message Handling :\n\n";
struct fsm_thread_args *pParam = (fsm_thread_args*)lpParam;
// fsm = new CSMManager(pParam-> ........ ); not important for the error
}
由于push_back()操作,pthread无法成功返回。如果我命令push_back循环,则线程可以成功返回并且程序退出处于有效状态。但是使用push_back循环,线程的返回不会成功。我认为一种内存损坏可能是原因,但我不知道如何解决这个问题!!
有人能帮助我吗?
非常感谢!