文件名称:shared_var
- 所属分类:
- Linux/Unix编程
- 资源属性:
- [C/C++] [源码]
- 上传时间:
- 2013-12-02
- 文件大小:
- 3kb
- 下载次数:
- 0次
- 提 供 者:
- 段*
- 相关连接:
- 无
- 下载说明:
- 别用迅雷下载,失败请重下,重下不扣分!
介绍说明--下载内容均来自于网络,请自行研究使用
在linux环境下编写一个控制台应用程序,程序中有一个共享的整型变量shared_var,初始值为0;创建一个线程并使其立即与主线程并发执行。新创建的线程与主线程均不断地循环,并输出shared_var 的值。主线程在循环中不断地对shared_var 进行加1操作,即每次循环shared_var 被加1;而新创建的线程则不断地对shared_var 进行减1 操作,即每次循环shared_var 被减1。观察程序运行的结果,并对你看到的现象进行解释。-In the Linux environment. Write a console application, in the program have a Shared shared_var integer variables, the initial value of 0 Create a thread and make it with the main thread immediately execute concurrently. The newly created thread and the main thread are continuously circulation, and the value of output shared_var. The main thread in a loop to add 1 shared_var continuously operating, namely each loop shared_var added 1 While the newly created thread continuously to minus 1 shared_var operation, namely each loop shared_var was minus 1. Observe the result of the program is running, and to explain the phenomenon of you see.
(系统自动生成,下载前可以参看下载内容)
下载文件列表
shared_var.c
shared_var.out