Any lightweight way for one thread to force another thread to suspend execution?

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Eric Smith
Date: Friday, June 20, 2008 - 4:54 pm

Is there any method for one thread to force another thread to suspend
execution, then later let it resume, that is lighter weight than using
signals?  I don't need it to be portable to anything other than Linux.
The suspend needs to be synchronous, but resume doesn't.

What I've thought about so far (but haven't tested) for thread A
to suspend thread B is to use a signal and two pthread conditions:

    Thread A                   Thread B
    -----------------------    -----------------------
    send signal to B

    wait on a cond 1

                               enter signal handler

                               signal cond 1

                               wait on cond 2

    wake up
    do stuff that needs
    thread B suspended

    signal cond 2

    continue                   wake up


Thanks for any suggestions!
Eric Smith

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Any lightweight way for one thread to force another thread ..., Eric Smith, (Fri Jun 20, 4:54 pm)
Re: Any lightweight way for one thread to force another th ..., Mikael Pettersson, (Tue Jun 24, 12:59 am)