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