8c4 Subj : Re: Challenge: Multithreading & Synchronization To : comp.programming.threads From : Maciej Sobczak Date : Sat May 21 2005 04:40 pm Giancarlo Niccolai wrote: >>Let's say there is no cout, but instead the "print" function: >> >>print("I'm doing something"); > > More. The terminal operation may be a LONG operation. It is not the point here. The point is that synchronizing threads is not necessarily about protecting accesses to some data, but also about orchestrating the work of multiple threads so that the overall sequence of actions results in well-defined program behaviour. In the case of output devices, the "well-defined" might just mean that the output is semantically meaningful when many "unit" operations are used. This example was given to motivate Uenal Mutlu to think in terms of operations, not in terms of separate (and possibly independent) objects. > If a terminal get > disconnected while accessed If you are concerned about this possibility, then that's fine - depending on your environment. Others might be concerned about spontaneously disconnecting hard drives or even CPUs (you may not believe, but I remember having disconnected hard drive whereas I do not remember any disconnected terminal). It was not the focus of this example, however. > Locking an > operation (print) to protect an object (terminal) is wrong. In this example, it is not the terminal (as a physical object) which was protected, but rather the "continuity" of the information that is printed. > You must find another way [...] The way exists, and it's simple, just look a > little further... If you are talking about "transactions", then no. No matter what (and how much effort you want to put into it), sooner or later you will have to call this print function and if done from many threads, the problem is still there. If you are talking about having a separate thread (or even process) that will be responsible for printing, then here also the problem is still there, just moved from one place to another. Anyway - it was not the point of this example. -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/ . 0