当前位置:网站首页>Visual studio2019 configuration uses pthread
Visual studio2019 configuration uses pthread
2022-08-11 06:32:00 【rest of my life love static】
一、下载pthread
pthreadThe url
下载pthread的最新版pthreads-w32-2-9-1-release.zip,然后解压,Will get the following three folder:
二、配置pthread
1、右键项目,选择属性
2、在VC++目录配置包含目录和库目录
包含目录:配置的是include所在的路径(D:\Android\c++\pthreads-w32-2-9-1-release\Pre-built.2\include)
库目录:配置的是lib所在的路径,If it's configuration is32位的平台,就选择D:\Android\c++\pthreads-w32-2-9-1-release\Pre-built.2\lib\x86;如果配置64位的平台,就选择D:\Android\c++\pthreads-w32-2-9-1-release\Pre-built.2\lib\x64



3、编写如下代码,并运行
#include <iostream>
// 必须的头文件
#include <pthread.h>
using namespace std;
#define NUM_THREADS 5
// 线程的运行函数
void* say_hello(void* args)
{
cout << "Hello Runoob!" << endl;
return 0;
}
int main()
{
// 定义线程的 id 变量,多个变量使用数组
pthread_t tids[NUM_THREADS];
for (int i = 0; i < NUM_THREADS; ++i)
{
//参数依次是:创建的线程id,线程参数,调用的函数,传入的函数参数
int ret = pthread_create(&tids[i], NULL, say_hello, NULL);
if (ret != 0)
{
cout << "pthread_create error: error_code=" << ret << endl;
}
}
//等各个线程退出后,进程才结束,否则进程强制结束了,线程可能还没反应过来;
pthread_exit(NULL);
}
3-1、Running will quote us the following error:
解决方案:
打开pthread.h文件,添加以下内容:
#define HAVE_STRUCT_TIMESPEC
#pragma comment(lib,"pthreadVC2.lib")

3-2、再次运行,Will quote us the following exception:
解决方案:原因是找不到对应的dll文件,Need to manually put the correspondingdll文件拷贝到对应的目录下
Pre-built.2\dll\x86下的文件拷贝到C:\Windows\SysWOW64目录下
Pre-built.2\dll\x64下的文件拷贝到C:\Windows\System32目录下
PS:Direct copy the correspondingdllFile to the corresponding directory,而不是dll文件夹的文件夹
再次运行,就成功了.
边栏推荐
- HTTP缓存机制详解
- USB中用NRZI来编码数据
- 微信和抖音都到十亿级用户了,作为产品经理的你们觉得哪个产品更成功?
- 2021-09-11 C语言 变量与内存分配
- Promise.race学习(判断多个promise对象执行最快的一个)
- 构建面向特征工程的数据生态 ——拥抱开源生态,OpenMLDB全面打通MLOps生态工具链
- Wisdom construction site safety helmet identification system
- Introduction of safety helmet wearing recognition system
- gerrit 配置SSH Key和账号、邮箱信息
- 如何快速转行做产品经理
猜你喜欢
随机推荐
贡献者任务第三期精彩来袭
博客目录
js写四位随机数能有多少种可能性?并列出所有可能性
防盗链——防止其他页面通过url直接访问本站资源
目标检测学习目录(持续更新)
实时特征计算平台架构方法论和基于 OpenMLDB 的实践
umi约定式路由规则修改
谨此留个纪念
产品版本号是如何确定的
论文解读TransFG: A Transformer Architecture for Fine-grained Recognition
音乐竞品分析:酷狗、QQ音乐、网易云、酷我、汽水音乐
C语言实现猜数字(附带源码,可直接运行)
开源机器学习数据库OpenMLDB贡献者计划全面启动
STM32-中断优先级管理NVIC
论文解读:跨模态/多光谱/多模态检测 Cross-Modality Fusion Transformer for Multispectral Object Detection
开源之夏 2022 火热来袭 | 欢迎报名 OpenMLDB 社区项目~
支付牌照是什么意思
weex入门踩坑
Error: Flash Download failed - “Cortex-M4“-STM32F4
CMT2380F32模块开发1-硬件








