2011-02-06 21 views
-2

好了,我打算这样做:c/C++:线程每1秒递减一个变量? (在Windows)

int seconds = 90; 

void *DecreaseSeconds(){ 

    while (seconds>-1) 
     { 
      seconds--; 
      sleep(1000); 
     } 

     return NULL; 
} 

    int main(int argc, char *argv[]){ 

     int threadid= pthread_create(&threads[i], NULL, DecreaseSeconds, NULL); 
     pthread_join(threadid, NULL); 

    } 

然而,我得到这个可怕的事情时,我尝试编译在Visual Studio 2008中

fatal error C1083: Cannot open include file: 'pthread.h': No such file or directory 

我想办法翻译这可以让Windows或使Visual Studio接受我的posix线程。

+0

你很幸运,窗口线程模型比posix更丰富! – 2011-02-06 17:18:12

回答

1

查找RTL函数_beginthreadex。

1

在Win32上没有POSIX线程支持。您需要使用Win32线程或支持两者的抽象。

相关问题