[英]Outputting variable from one thread to other
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)?
如何在另一个线程/线程外访问该变量的实时值(不处于无限循环中)?
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.
但是,您需要注意线程同时读取和写入一个变量时的锁定条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.