我正在编写一个运行两个线程的Linux下的小应用程序(embedded在ARM上)。 我在函数中做了一个“popen”,这为进入函数的第二个线程创build了一个死锁。 但是,首先进入函数的第一个线程仍然正常运行。
这里是一些代码示例:
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; int sendCommand( const std::string& command,std::string& answer) { FILE* fd; // File descriptor to command output char answer_c[COMMAND_BUFFER_SIZE]; // The answer as char[] int answerLength = 0; // The length of the answer pthread_mutex_lock( &mutex1 ); // A probe cout << "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV" << endl; fd = popen(command.c_str(),"r"); // <- Second thread entering is stuck here ... if(fd <= 0) { cout << "Couldn't popoen !" << endl; return -1; } // A probe,never showed by second thread entering the function cout << "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZzz" << endl; // ... Omitted code ... // Close the file descriptor pclose(fd); pthread_mutex_unlock( &mutex1 ); }
我真的有这样的感觉,我失去了一些重要的东西。 popen怎么会发生死锁? 问题是来自标准的libc还是Linux内核?
任何指针强烈感谢!
我的文件服务器程序已经停止僵尸进程
如何从控制台读取行并将其存储到c + +中的string?
(Linux / X11)透明窗口上的透明opengl对象以纯色背景显示窗口背后的内容
控制Windows 7的任务栏分组为我的应用程序
Linux的C – 获取locking键状态'
问候,
如何停止运行阻塞永久循环的QThread?
帮助这个编译错误
W8电话System.Xml.XmlException&
由于popen做了一个fork(这不是线程安全的),所以popen也不是线程安全的。
这个问题和答案可能会帮助你一点。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。