Re: New essay: The Best Synchronization is No Synchronization



Hi Joe,

Nice write up and I appreciate your thoughts. I confess that inter and even intra thread communication is one of things that confuses me often. It is especially true when one uses libraries that may start their own threads that call back into functions in your thread. The classic syncronization techniques fall apart if everyone is not using them correctly. It only takes one block to ruin your day :o)

I typically set flags in the thread that tell it something needs to happen whenever it would be appropriate. Many of my threads run as state machines so the flag just introduces a new event into the state queue that happens in turn. This is true of things like deleting or adding an item to a list owned by the thread, modifying a value, things like that.

I appreciated your article. Thanks.

Tom

"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message news:tiic63hnr2cpcnlqdo8dblobf9kvrbrasd@xxxxxxxxxx
In response to an earlier post saying that messages should not be used for synchronization
and that primitives like mutexes, events, and semaphores were better suited, (note also
that CRITICAL_SECTIONs had been omitted from the list, probably an oversight, and timers
had been included, for reasons I cannot ascertain because timers have nothing to do with
synchronization). I offer a counterargument: these primitives are the assembly code of
synchronization, and mechanisms like messages and I/O Completion Ports provide much better
alternatives most of the time. We should be searching for higher-level mechanisms.

I discuss two of my favorite non-synchronization mechanisms for mutual exclusion: the
Positive Handoff Protocol and the Central Controller Protocol, both of which are easier to
use and neither of which uses an event, semaphore, mutex, or CRITICAL_SECTION. I also
suggest that when these *are* needed they should be hidden inside classes so the
programmer never needs to see them.

http://www.flounder.com/no_synchronization.htm
joe
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

.



Relevant Pages

  • Re: Locking out student IM etc.
    ... > mechanisms certainly already existed. ... Check out the Windows IT Pro ... Their Web site is www.windowsitpro.com. ... > MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: interprocess communciation
    ... - message queue: synchronization and information exchange between 2 ... - events: synchronization between 2 processes/threads. ... > synchronisation mechanisms in windows ce. ...
    (microsoft.public.windowsce.platbuilder)
  • Locking out student IM etc.
    ... mechanisms certainly already existed. ... Their Web site is www.windowsitpro.com. ... So the mechanism not only exists, but is apparently built into Windows already! ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • New essay: The Best Synchronization is No Synchronization
    ... In response to an earlier post saying that messages should not be used for synchronization ... and that primitives like mutexes, events, and semaphores were better suited, (note also ... We should be searching for higher-level mechanisms. ...
    (microsoft.public.vc.mfc)
  • Re: multithread question
    ... and the value is never changed for the lifetime of all the threads that ... and the timing of this relative to other readers is irrelevant (that is, ... misses it by one memory cycle no harm is done), then no synchronization is required. ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)