no message

master
zcy 2021-11-29 15:33:44 +08:00
parent d425550735
commit 218e49fa7b
1 changed files with 12 additions and 5 deletions

View File

@ -78,7 +78,7 @@ void do_print_id(int id) {
}
void go(){
gReady = true;
gReady = false;
gCv.notify_all(); // 唤醒所有线程.
}
@ -93,6 +93,10 @@ int TestConditionVariable() {
for (int i = 0; i < 10; ++i)
threads[i] = std::thread(do_print_id, i);
std::cout << "10 threads ready to race...\n";
Sleep(1000);
go_once();
go_once();
go_once();
go_once();
for (auto & th:threads)
@ -252,6 +256,12 @@ class ASyncProcess {
ret = t(args...);
});
}
ASyncProcess(Function t,Ret &ret){
std::cout<<"ASyncProcess construct"<<std::endl;
mThread = new std::thread([t,&ret](){
ret = t();
});
}
bool Finish(){
return m_finish;
}
@ -264,8 +274,6 @@ class ASyncProcess {
std::thread *mThread;
};
template<typename R, typename... Args>
int test2(R(&f)(Args...), R& ret_param, Args... args) {
ret_param = f(args...);
@ -279,10 +287,10 @@ int test2(void(&f)(Args...), Args... args)
return 0;
}
int ss(int p,int w){
return 1;
}
int main()
{
TestConditionVariable();
@ -293,6 +301,5 @@ int main()
},result,22);
getchar();
std::cout<<result;
}