shared_var
所属分类:Linux/Unix编程
开发工具:Unix_Linux
文件大小:3KB
下载次数:5
上传日期:2013-12-02 19:10:01
上 传 者:段昀
说明: 在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.)
近期下载者:
相关文件:
收藏者: