两个线程,一个是主线程(mainthread), 一个是工作线程(workthread)。当工作线程工作完后,可不可以休眠,直到主线程唤醒他。workthread
{
while ( 1)
{
do sth.
if finish, sleep.
}
}============================
mainthread
while ( 1)
{
if something happened, tell workthread . let it run.
do other thing.
}现在的问题是,当工作线程工作完后,如何让它休眠; 当主线程让它工作,又可以唤醒它。你可以用 mutex 等来实现。
{
while ( 1)
{
do sth.
if finish, sleep.
}
}============================
mainthread
while ( 1)
{
if something happened, tell workthread . let it run.
do other thing.
}现在的问题是,当工作线程工作完后,如何让它休眠; 当主线程让它工作,又可以唤醒它。你可以用 mutex 等来实现。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货