multithreading - 无法从编程书上运行我的代码(c++)

标签 multithreading visual-c++ compilation

我得到了一本新的编程书(cameron hughes,tracey hughes 的多核编程)。
到目前为止,我还没有让他们的任何程序运行他们的书说它应该在 99% 的计算机上运行,​​所以我有点困惑,但在他们书中每个程序的末尾,他们都有“编译和链接指令”......我需要输入吗?它看起来像这样“C++ -oguess_itguess_it.cc”。我现在运行的代码是:

#include <iostream>
#include <windows.h>
#include <string>
#include <spawn.h>
#include <sys/wait.h>

using namespace std;

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

 pid_t ChildProcess;
 pid_t ChildProcess2;
 int RetCode1;
 int RetCode2;
 int Value;
 RetCode1 = posix_spawn(&ChildProcess,"find_code",NULL,
                        NULL,argv,envp);
 RetCode2 = posix_spawn(&ChildProcess2,"find_code",NULL,
                        NULL,argv,envp);
 wait(&Value);
 wait(&Value);
 return(0);
 }

我正在运行 Windows 7(32 位),AMD athion x2 7550 双核处理器,VC++ 2008 Express 版。
我收到以下错误: fatal error C1083:无法打开包含文件:'spawn.h':没有这样的文件或目录

任何人都知道为什么我不能让我的代码运行?我需要下载一些东西吗?因为我读了这本书,没有看到任何关于下载任何东西的信息,但我可能是错的。 :(

最佳答案

看起来那本书正在使用 POSIX 线程。 Visual Studio 默认使用 Windows 线程,它具有完全不同的 API。

您很可能只需要获取 POSIX Thread library for Windows 的副本.这将包括 spawn.h和适当的 lib 文件供您使用。

关于multithreading - 无法从编程书上运行我的代码(c++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2421836/

相关文章:

multithreading - 乱序执行和重新排序 : can I see what after barrier before the barrier?

c - MS VS 2008 中 __declspec(dllimport) 的用法

c++ - 关于将 FFmpeg 编译成静态构建(仅限 .lib 文件)以便在 Visual Studio 中使用的说明?

android - 无法在Android Studio上编译Apk

编译和链接纯 C 和 CUDA 代码 [警告 : implicit declaration of function]

c - 使用 pthread 和同步

java - 在Java中使用基于双重检查锁定的单例是否安全?

c - 辅助进程完成时终止 Main

c++ - 作为类私有(private)成员的无名结构/union

unit-testing - CppUnit 能否以 HTML 或 XML 格式报告结果?