c多线程不加锁demo
2024-09-01 15:23:50
//
// Created by gxf on 2019/12/13.
//
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h> int shareInt = 0;
void increase_num(void); int main() {
int ret;
pthread_t thread1, thread2, thread3; ret = pthread_create(&thread1, NULL, increase_num, NULL);
ret = pthread_create(&thread2, NULL, increase_num, NULL);
ret = pthread_create(&thread3, NULL, increase_num, NULL); pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
pthread_join(thread3, NULL); printf("sharedInt:%d\n", shareInt); return 0;
} void increase_num(void) {
long i, tmp;
for (i=0; i <= 100000; i++) {
tmp = shareInt;
tmp = tmp + 1;
shareInt = tmp;
}
}
最新文章
- StgCreateDocfileOnILockBytes复合文档
- csharp: InvokeHelper
- poj1062 最短路
- IOS 中runtime 不可变数组__NSArray0 和__NSArrayI
- [剖析Javascript原理]1.原生数据类型
- AUC计算方法总结
- Angular2 使用CLI创建新项目
- springboot整合mybatis出现的一些问题
- jQuery.extend 与 jQuery.fn.extend
- 找到多个与名为“Home”的控制器匹配的类型的解决方案
- 使用Hibernate Validator来帮你做数据校验
- js自定制周期函数
- mysql常用查询语句
- webservice的 发布
- 给trac的ticket添加提交时字段验证
- 分析ReentrantLock的实现原理
- ruby中的三目操作符和include?操作
- 记录一次代码错误,elastic search的INDEX需要使用小写字母
- 多线程博文地址 http://www.cnblogs.com/nokiaguy/archive/2008/07/13/1241817.html
- lucene&;solr学习——solr学习(二) Solr管理索引库
热门文章
- EM算法之不同的推导方法和自己的理解
- SpringBoot开发
- hfile.block.cache.size - hbase调优
- 后ARM时代,嵌入式工程师的自我修养
- 乐字节Java反射之四:反射相关操作
- [转帖]降低 80% 的读写响应延迟!我们测评了 etcd 3.4 新特性(内含读写发展史)
- 学习Elasticsearch原理笔记
- 剑指offer56:删除链表中重复的结点,排序的链表中,删除重复的结点不保留,返回链表头指针。 例如,链表1->;2->;3->;3->;4->;4->;5 处理后为 1->;2->;5
- stal 安装
- Asp.net core 学习笔记 2.2 migration to 3.0