ThreadPool icon indicating copy to clipboard operation
ThreadPool copied to clipboard

Unexpected stuck thread

Open DeepLearnerYe opened this issue 1 year ago • 2 comments

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?

DeepLearnerYe avatar Jan 18 '24 02:01 DeepLearnerYe

sorry, I can not reproduce your error code in a win11 and msvc environment. Could you please use the godbolt to reproduce the error.

sunbuny avatar Mar 22 '24 08:03 sunbuny