本文介绍了如何同步两个线程使用的bool / int变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys,



我知道它非常简单和基本的问题,想知道答案。

我是线程概念的新手。



问题:假设,我有一个bool变量让我们说 bool var ,两个线程可以使用这个变量。



我应该如何同步?



根据我的知识就是这样,我们可以使用互斥锁来锁定变量。这将确保当线程使用变量时,其他线程将无法访问它。





其他解决方案是什么。



请帮忙。



问候,

欢乐

Hello Guys,

I know its very simple and basic question thought would like to know answer.
I am newbie in threading concepts.

Question: Suppose, I have a bool variable lets say bool var, Two threads can use this variable.

How should I synchronize it?

As per my knowledge goes,we can use mutex to lock variable. This will ensure that when a variable is getting used by a thread, other thread will can not access it.


What are other solutions.

Please help.

Regards,
Joy

推荐答案


这篇关于如何同步两个线程使用的bool / int变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 19:18
查看更多