thread-pool: Cannot be used inside the class
I found out that I can’t call threadpool inside class. If I call it in main function in app (like your example) or in dll like this:
void sleep_half_second(const size_t& i, synced_stream* sync_out)
{
std::this_thread::sleep_for(std::chrono::milliseconds(500));
sync_out->println("Task ", i, " done.");
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
thread_pool* pool;
synced_stream sync_out;
int i = 1;
pool = new thread_pool(12);
pool->push_task(sleep_half_second, i, &sync_out);
return TRUE;
}
It’s OK, doesn’t generate error c2064. But if using it in class, it still generates error c2064.
Please help me fix this, I need to call it inside the class
doubleRsi.zip Thank you very much
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (7 by maintainers)
Good thanks! I just wanted to confirm that you didn’t find some other tweaks/fixes.
Duely noted !
Glad to hear that! Please feel free to let me know if you have any more suggestions or feature requests 😃
PS: After doing some testing I realized the difference between
test_objectand&test_objectin the second argument. The former will create a copy of the object, while the latter will be a pointer to the actual object. This difference is extremely important when making changes to the object, since any changes made to the copy will not be made in the original object. I corrected the code above to fix that.Okay, I managed to make
submit()work as well:Here’s the updated test program:
I will incorporate this into the next release, along with a few other changes I’ve been working on.
EDIT: Fixed the above test program so it works with all compilers (previously it only worked with GCC).
Thank you very much, I have successfully compiled with lambda