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

Threads



Okay, I have a terribly simple way to do this. Basically in something like
a widget set there are a disturbing number of places you need to grab a
lock (every function call). So my thought is just mutex the whole thing
and be done with it. Simple, fast to implement and easy to understand.

The various event handlers will grab the lock on entry. This serializes
the whole thing, especially the graphics handling in one neat package. It
doesn't provide ideal speed but it quite nicely handles the goal -- easy
to write blocking routines.

The worker thread would look like:
  

  void Thread(void *)
  {
      <Do Stuff>

      // Update display
      {
         GrabMutex WidgLock(Widget::WidgetMutex);
         Dialog->Progress->Value(I);
         SyncFD->Pulse();
      }
  }  

SyncFD is a non-blocking pipe that feeds into the main threads select
loop. When 'Pulsed' it will break the select loop and cause pending
redraws and 'sync notifications' to be performed in the context of the
main thread. 

I think this provides the simplest to implement and explain thread system
that covers pretty much every case I could want.

Jason


Reply to: