我正在写一个关于死锁及其检测的代码,我在Ubuntu 12.10,64位上使用eclipse Juno C/C++。 问题是,当我使用C++睡眠线程冲突
睡眠(1)
,我得到当我建立这个
睡眠并没有在此范围内
声明项目,我试图包括
包括< unistd.h>中
,但随后喜欢
在pthread_join
所有的并行线程功能,让我像
未定义的引用在pthread_join错误
,without #include < unistd.h>这样的错误不会显示出来。
示例代码:
#include <unistd.h>
#include <iostream>
#include <semaphore.h>
#include <queue>
#include <stdlib.h>
using namespace std;
pthread_mutex_t mutex;
sem_t sem; //used for writing in the console
.......
void cross(Batman b) {
// code to check traffic from the right, use counters, condition
sem_wait(&sem);
cout << "BAT " << b.num << " from " << b.direction << " crossing" << endl;
sem_post(&sem);
sleep(1);
}
........
P.S.我遵循这些说明,以获得pthreads在其他项目中工作,我也为这个项目做了同样的工作 http://blog.asteriosk.gr/2009/02/15/adding-pthread-to-eclipse-for-using-posix-threads/
p.s.我正在和一位朋友一起工作这个项目,我使用了他使用的相同代码,但仍然得到这些错误,而他并没有