我看到这个问题Simple example of threading in C++ 但我的问题是,我想在Windows 32中运行此程序,似乎Pthread无法识别在Windows!请告诉我什么是问题?这是我的错误: 致命错误C1010:查找预编译头时出现意外的文件结尾。 ?你忘了“#包括文件‘StdAfx.h’”添加到您的源(我加的#include“StdAfx.h中,但它仍然 不工作!)Windows线程与C++
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#define NUM_THREADS 5
void *PrintHello(void *threadid)
{
long tid;
tid = (long)threadid;
printf("Hello World! It's me, thread #%ld!\n", tid);
pthread_exit(NULL);
}
int main(int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc;
long t;
for(t=0;t<NUM_THREADS;t++)
{
printf("In main: creating thread %ld\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
/* Last thing that main() should do */
pthread_exit(NULL);
}
你看了这个错误吗? – SLaks
我添加了#include“StdAfx.h”,但它仍然不能识别pthread! – Sara
现在你包含了什么错误“StdAfx.h”? – ChrisF