#include
#include
#include
#include
#include
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t empty = PTHREAD_COND_INITIALIZER;
pthread_cond_t full = PTHREAD_COND_INITIALIZER;
char buf[256];
int main()
{
pthread_t t1,t2;
void * put_buf(void *);
void * get_buf(void *);
pthread_mutex_lock(&lock);
pthread_cond_signal(&empty);
pthread_create(&t1, NULL, put_buf, NULL);
pthread_create(&t2, NULL, get_buf, NULL);
pthread_join(t1, NULL);
pthread_join(t2, NULL);
return 0;
}
void *put_buf()
{
while (true)
{
pthread_cond_wait(&empty, &lock);
printf_s("empty flag is raised\n");
pthread_mutex_lock(&lock);
printf_s("input: \n");
gets_s(buf);
pthread_mutex_unlock(&lock);
pthread_cond_signal(&full);
}
}
void *get_buf(){
Sleep(2);
while (true)
{
pthread_cond_wait(&full, &lock);
printf_s("full flag is raised");
pthread_mutex_lock(&lock);
printf_s("output:\n");
pthread_cond_signal(&empty);
}
}
出现问题:错误 1 error LNK2019: 无法解析的外部符号 "void * __cdecl put_buf(void *)" (?put_buf@@YAPAXPAX@Z),该符号在函数 _main 中被引用 c:\Users\陌桑时代shine\documents\visual studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\源.obj ConsoleApplication2
错误 2 error LNK2019: 无法解析的外部符号 "void * __cdecl get_buf(void *)" (?get_buf@@YAPAXPAX@Z),该符号在函数 _main 中被引用 c:\Users\陌桑时代shine\documents\visual studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\源.obj ConsoleApplication2