【发布时间】:2014-02-01 10:40:40
【问题描述】:
我在同一个程序中有 main() 和线程。
有一个名为“status”的变量,可以获取多个值
我需要当变量发生变化时,通知线程(线程cnat等待状态变量,它已经在做流利的任务了)。
有没有简单的方法可以做到这一点?类似于中断?信号呢?
main里面的函数:
int main()
{
char *status;
...
...
while (1)
{
switch (status)
{
case: status1 ...notify the thread
case: status2 ...notify the thread
case: status3 ...notify the thread
}
}
}
如果有人能给我一个例子,那就太好了! 谢谢!
【问题讨论】:
-
一次或多次?
-
nofify thread?意味着您通知线程处理更新的status值? -
不要在 switch 语句中使用
char *。 -
次数..不管多少..我需要照顾“状态”变量的变化,每个状态都是我需要采取的不同行动。
-
让线程检查状态的值,或者你的意思是一个回调函数?
标签: c++ c multithreading pthreads