ThreadPool
ThreadPool copied to clipboard
Unexpected stuck thread
The thread is running well when the function is simple. However, I encountered a stuck thread using my own function. Here is a simple example.
// running perfectly good
thread_pool->enqueue([]()
{
while(1)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
std::cout << "thread running...." << std::endl;
}
});
// I can see "myFunction() running". But my logic never starts to execute.
void myFunction()
{
std::cout << "myFunction() running" << std::endl;
while(1)
{
// some logic...
}
}
thread_pool->enqueue([]()
{
myFunction();
});
I created a thread myself to run my function, and it succeeded. So, that should not be the problem of my funtion, maybe there's a bug or something in the threadpool?
sorry, I can not reproduce your error code in a win11 and msvc environment. Could you please use the godbolt to reproduce the error.