linux 程序 共享变量,shared_var

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.)

近期下载者:

相关文件:

收藏者:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值