thread-pool icon indicating copy to clipboard operation
thread-pool copied to clipboard

Cannot release, possible deadlock when exit ...

Open chenscottus opened this issue 2 years ago • 6 comments

Stuck in ~thread_pool() => threads_[i].join();

145 pthread_join_common.c: No such file or directory. #0 __pthread_clockjoin_ex (threadid=281473323018496, thread_return=0x0, clockid=0, abstime=, block=) at pthread_join_common.c:145 #1 0x0000aaaaaadded30 in std::thread::join() () #2 0x0000aaaaaabba198 in std::jthread::join() (this=0xffff9804fe90) at /usr/include/c++/11/thread:160 #3 std::jthread::~jthread() (this=0xffff9804fe90, __in_chrg=) at /usr/include/c++/11/thread:130 #4 dp::thread_pool<std::function<void ()>, std::jthread>::~thread_pool() (this=0xffff9e7c6c58, __in_chrg=) at /home/dev/projects/vcam/project/Tracker/../common/thread_pool/thread_pool.h:

Thanks!

-Scott

chenscottus avatar Aug 25 '23 23:08 chenscottus

If I change the code to, it will like work.

		int threads_size = 0;

		threads_size = threads_.size();
		for (std::size_t i = 0; i < threads_size; ++i) {
			threads_[i].request_stop();
		}

		threads_size = tasks_.size();
		for (std::size_t i = 0; i < threads_size; ++i) {
			tasks_[i].signal.release();
		}

		threads_size = threads_.size();
		for (std::size_t i = 0; i < threads_size; ++i) {
			//threads_[i].request_stop();
			//tasks_[i].signal.release();
			if (threads_[i].joinable() == true)
			{
				threads_[i].join();
				//threads_[i].~jthread();
			}
		}

chenscottus avatar Aug 26 '23 00:08 chenscottus

Thanks for the report.

Can you post what your task looks like that you're running on the thread pool?

DeveloperPaul123 avatar Aug 26 '23 02:08 DeveloperPaul123

dp::thread_pool<>* dp_pool_vars; ... dp::thread_pool dp_pool(32); dp_pool_vars = &dp_pool; ... dp_pool_vars->enqueue(write_frames_original_task, &wf_original_args_main); ... ... dp_pool.~thread_pool(); ....

chenscottus avatar Aug 28 '23 16:08 chenscottus

Few things:

  • Why are keeping a pointer to the thread pool?
  • When the thread pool goes out of scope the deconstructor is automatically called. There's not need to call the thread pool dtor directly.
  • Can you post the actually code that's doing the work? The lock may be due to that code.

DeveloperPaul123 avatar Aug 28 '23 16:08 DeveloperPaul123

  1. I need to use the thread pool in different classes and function. I use only one thread pool. And I need to declare it first and later, initialize it. That is why I need a pointer
  2. correct: When the thread pool goes out of scope the deconstructor is automatically called. There's not need to call the thread pool dtor directly.
  3. my project is too big, the zip of the source code is more than 1MB.
  4. I just use enqueue function to run: dp_pool_vars->enqueue(write_frames_original_task, &wf_original_args_main);
  5. I have been runing a few days, there is no problem.
  6. The only problem is when the app finish, it need to release the resources.

chenscottus avatar Aug 28 '23 16:08 chenscottus

Okay no problem, I see.

One possible issue is that you're using enqueue() but you're not using the returned future. Consider using enqueue_detach().

DeveloperPaul123 avatar Aug 28 '23 17:08 DeveloperPaul123

Any updates on this issue? Are you still facing problems?

DeveloperPaul123 avatar Apr 26 '24 15:04 DeveloperPaul123

Thanks, no problem now!

On Fri, Apr 26, 2024 at 8:12 AM Paul T @.***> wrote:

Any updates on this issue? Are you still facing problems?

— Reply to this email directly, view it on GitHub https://github.com/DeveloperPaul123/thread-pool/issues/52#issuecomment-2079586392, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHZOKZQLK2D34EZHZDEJHLY7JVFDAVCNFSM6AAAAAA37D7B56VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZZGU4DMMZZGI . You are receiving this because you authored the thread.Message ID: @.***>

chenscottus avatar Apr 26 '24 15:04 chenscottus