将变量从一个线程输出到另一个线程
我有一个线程正在无限循环运行,不断更新变量。如何在另一个线程/线程外部访问该变量的实时值(而不处于无限循环中)?
I have a thread that has an infinite loop running, updating a variable constantly. How can I access the live value of that variable in an another thread/outside of the thread (without being in an infinite loop)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的方法是使用全局变量。
但是,当线程同时读取和写入一个变量时,您需要了解锁定条件。
例如,有一个很好的手册。
the best way to do it is to use global variables.
But, you need to be aware of the lock conditions when threads are reading and writing to one variable at once.
There is a good manual for example.