Visual Studio中的pthread_create错误
pthread_create Error in Visual Studio
大家好,我正在使用Visual Studio 2010,在让这个理发店程序工作时遇到了问题。
我收到这个错误
pthread_create
:无法将参数3从void *(__cdecl *)(void)
转换为void *(__cdecl *)(void *)
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <Windows.h>
#define seats 6
void *customerMaker();
void *barberShop();
void *waitingRoom();
void checkQueue();
pthread_mutex_t queue_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t wait_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t sleep_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t barberSleep_cond = PTHREAD_COND_INITIALIZER;
pthread_cond_t barberWorking_cond = PTHREAD_COND_INITIALIZER;
int returnTime=5,current=0, sleeping=0, iseed;
int main(int argc, char *argv[])
{
iseed=time(NULL);
srand(iseed);
//declare barber thread;
pthread_t barber,customerM,timer_thread;
pthread_attr_t barberAttr, timerAttr;
pthread_attr_t customerMAttr;
//define barber, and cutomerMaker default attributes
pthread_attr_init(&timerAttr);
pthread_attr_init(&barberAttr);
pthread_attr_init(&customerMAttr);
printf("n");
//create cutomerMaker
pthread_create(&customerM,&customerMAttr,customerMaker,NULL);
//create barber
pthread_create(&barber,&barberAttr,barberShop,NULL);
pthread_join(barber,NULL);
pthread_join(customerM,NULL);
return 0;
}
void *customerMaker()
{
int i=0;
printf("*Customer Maker Created*nn");
fflush(stdout);
pthread_t customer[seats+1];
pthread_attr_t customerAttr[seats+1];
while(i<(seats+1))
{
i++;
pthread_attr_init(&customerAttr[i]);
while(rand()%2!=1)
{
Sleep(1);
}
pthread_create(&customer[i],&customerAttr[i],waitingRoom,NULL);
}
pthread_exit(0);
}
void *waitingRoom()
{
//take seat
pthread_mutex_lock(&queue_mutex);
checkQueue();
Sleep(returnTime);
waitingRoom();
}
void *barberShop()
{
int loop=0;
printf("The barber has opened the store.n");
fflush(stdout);
while(loop==0)
{
if(current==0)
{
printf("tThe shop is empty, barber is sleeping.n");
fflush(stdout);
pthread_mutex_lock(&sleep_mutex);
sleeping=1;
pthread_cond_wait(&barberSleep_cond,&sleep_mutex);
sleeping=0;
pthread_mutex_unlock(&sleep_mutex);
printf("ttttBarber wakes up.n");
fflush(stdout);
}
else
{
printf("tttBarber begins cutting hair.n");
fflush(stdout);
Sleep((rand()%20)/5);
current--;
printf("ttttHair cut complete, customer leaving store.n");
pthread_cond_signal(&barberWorking_cond);
}
}
pthread_exit(0);
}
void checkQueue()
{
current++;
printf("tCustomer has arrived in the waiting room.ttttttt%d Customers in store.n",current);
fflush(stdout);
printf("ttCustomer checking chairs.n");
fflush(stdout);
if(current<seats)
{
if(sleeping==1)
{
printf("tttBarber is sleeping, customer wakes him.n");
fflush(stdout);
pthread_cond_signal(&barberSleep_cond);
}
printf("ttCustomer takes a seat.n");
fflush(stdout);
pthread_mutex_unlock(&queue_mutex);
pthread_mutex_lock(&wait_mutex);
pthread_cond_wait(&barberWorking_cond,&wait_mutex);
pthread_mutex_unlock(&wait_mutex);
return;
}
if(current>=seats)
{
printf("ttAll chairs full, leaving store.n");
fflush(stdout);
current--;
pthread_mutex_unlock(&queue_mutex);
return;
}
}
waitingRoom
必须接受指针参数。请参阅pthread_create
文档。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 错误:(-210:不支持的格式或格式组合)功能'create'中的硬件视频解码器不支持视频源
- 错误:'create'不是 'cv::Tracker' 的成员
- libgit2:git_clone() 失败并出现"failed to create ssl object"错误
- Visual Studio 2015:获取"non standard syntax, use '&' to create a pointer to member"错误
- 错误未定义对"BP::D evice::Create(std::string const&)"的引用
- MFC 错误仅在发布模式下"Failed to create an empty document"
- 了解重载运算符。收到"non-standard syntax; use '&' to create a pointer to a member"错误
- 来自Opencv Mat::create的段错误
- sqllite CREATE INDEX执行返回错误
- Create()返回错误代码1406
- "cannot create .moc/main.moc "有一个错误,当我编译Qt5.7的mysql驱动程序时
- Visual Studio 2015 中的"non-standard syntax; use '&' to create a pointer to member"错误
- Gdk::Pixmap在create()上给我一个分段错误