Unexpected stuck thread

Author: DeepLearnerYeCreated Jan 18, 2024Updated Oct 18, 2024

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?