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

Unexpected stuck thread #110

Open
DeepLearnerYe opened this issue Jan 18, 2024 · 2 comments
Open

Unexpected stuck thread #110

DeepLearnerYe opened this issue Jan 18, 2024 · 2 comments

Comments

@DeepLearnerYe
Copy link

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?

@sunbuny
Copy link

sunbuny commented Mar 22, 2024

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

@Smalldy
Copy link

Smalldy commented Oct 18, 2024

what's your num thread argument value ? if you set it to 1, then you will get stuck, because all the task will run in one thread, so that they will run one by one.

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

3 participants