This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Suspend/resume a pthread thread


On Tue, May 11, 2010 at 12:38:17AM -0400, Bharath Ramesh wrote:
> I believe currently there exists no such pthread API like
> pthread_continue/resume/suspend. What would be the ideal way to
> suspend/resume a thread from another thread in a multi-threaded application.
> Of course for this to work one should ensure that program will not deadlock,
> this is something I can guarantee as a programmer. One cannot use
> pthread_kill as no thread can individually block SIGSTOP. I was wondering if
> any API similar to one present in HP-UX [1] exists for NPTL.

I don't really see a great value in this (after all, thread cancellation
is already extremely hairy stuff in itself, introducing more of this
stuff sends chills down my spine), can you present some practical
usecase that would benefit from this and could not be easily done
otherwise?

Usually, threads are fairly self-contained tasklets that don't really
need to be stopped temporarily at random points, or revolve around a
certain loop and can easily check for suspend condition at the loop
head.

> I could
> probably use something like SIGUSR1/SIGUSR2 to sched_yield till the
> condition for resume is satisfied, this would only move my thread to the end
> of the ready queue. I wanted to know if there was any better way of
> achieving this.

Why not wait on a semaphore or a condvar for the green light instead of
looping sched_yield()?

-- 
				Petr "Pasky" Baudis
When I feel like exercising, I just lie down until the feeling
goes away.  -- xed_over


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]