Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CreateThread 里传入类成员方法,如果调用CreateThread的方法退出过快,线程将不会启动 #3

Open
fengshangren opened this issue Jan 5, 2022 · 1 comment

Comments

@fengshangren
Copy link

例子:
这样线程将不会被执行。
call_thunk::thunk thunk<cb_type>(obj, &TestClass::fun);
CreateThread ( NULL , 0 , (LPTHREAD_START_ROUTINE )thunk, NULL , 0 , NULL );
return;

这样线程才会成功执行
call_thunk::thunk thunk<cb_type>(obj, &TestClass::fun);
CreateThread ( NULL , 0 , (LPTHREAD_START_ROUTINE )thunk, NULL , 0 , NULL );
Sleep(100);
return;

@ruoleng
Copy link

ruoleng commented Jan 5, 2022

call_thunk::thunk thunk<cb_type>(obj, &TestClass::fun);
改为全局变量。
临时变量去到线程中就不可用了,注意线程安全。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants