Subj : Re: Challenge: Multithreading & Synchronization To : comp.programming.threads From : Maciej Sobczak Date : Fri May 20 2005 10:25 pm Uenal Mutlu wrote: >>The terminal? > > Of course: > Question: Is in your application the terminal shared by multiple threads? > Answer: YES > Then: make the terminal lockable No. I have specifically used the puts() function to show you that there are cases where there might be no "object" which you can "physically" grab and wrap. This example was extremely simple, yet you have rejected to see the point and have converted the example to use cout - just to fit it to your broken idea? Let's say there is no cout, but instead the "print" function: print("I'm doing something"); Show me how you make it lockable. Forget about streams, cout, stdout or any other object. Yes, you can make a class around this single function, create an object out of it (singleton or monostate) and then make it lockable, but it is still not the point - I can have many different "unit" actions (even belonging to different libraries) that I want to orchestrate to achieve some sequence that will be well-defined according to some protocol. Mutex per object will not help me with this. > How: of course by a mutex; see below >>Again - think in terms of actions, not in terms of objects >>(multithreading is about "doing", not about "values"). Then you will >>maybe discover that your concept of embedding mutexes in all value >>objects brings you nowhere. > > Time will prove you wrong. Time's already proved that I was wrong a few times in my life, so I'm ready. > But, in case you really don't know: > > In your case actually you want to use 2 objects in a shared manner: > 1) the output stream > 2) the vector In this specific case, fine. > Using the "mutex per object" method gives you a simple and elegant solution: Except when there is no object? (see the print function above) > Some people will argue that just 1 mutex would be sufficient. Let them think so. > The above is the recommended method. Could you reference some books or articles recommending it? -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/ .