Re: GEvent - Proposal for a new threading structure for GLib

On Fri, Nov 17, 2006 at 11:16:12AM -0500, Matthew Barnes wrote:
> Working full-time on Evolution, I find myself doing a fair amount of
> multi-threaded programming.  I've often wished GLib had something
> equivalent to Python's threading.Event class [1], which is a simple but
> useful mechanism for signaling an event to other threads.
> I'd like to propose such a mechanism for GLib, which I call a GEvent.
> A GEvent manages a mutex-guarded boolean and condition variable.
> Threads can set, test, clear, and block on a GEvent without worrying
> about the details of locking/unlocking or checking a condition variable
> properly.
> The most compelling use case I see for this in Evolution is for message
> passing.  Threads that push messages to an asynchronous queue or a
> thread pool are often interested in knowing when the message has been
> processed and its output is available.  A simple way to coordinate this
> would be to embed a GEvent in each message and have the thread
> processing the message set the event when it is finished.  That would
> then wake up any threads that are blocked on the event.

Isn't this what a semaphore is?

> There's obviously many other use cases.  Any textbook on concurrent
> programming should provide plenty of examples.
> I've attached a patch that implements and documents GEvent.  It closely
> mimics the Python class, so I won't bother describing the API here.
> Would this be a worthwhile addition to GLib?

I would suggest that somebody look at what the full requirements are,
and not mimic Python. :-)

I think a semaphore does what you are asking for, and can be implemented
more efficiently. One person raises the flag, and the other person wakes
up because the flag is raised. There are a few ways to do this...


mark mielke cc / markm ncf ca / markm nortel com     __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]