Jos Timanta Tarigan wrote:
> in main creating thread Hello world! its me thread 32
>
> which means that the thread was cut before finishing one line of command. 
>
> Is there any way to set the thread not to cut other thread while doing one 
> single command? are there a way to tell other thread "DONT CUT ME WHILE DOING 
> THIS/FROM THIS LINE TO THAT LINE!" in a line(s) of code?
>   

You need to use a thread-safe I/O library. Not all of them behave as 
expected when accessed by multiple threads.

You give up some performance, but gain consistency. Basically, the I/O 
library will handle concurrency internally through some locking 
mechanism, so one thread will block until another completes its I/O.

In your source code, you have lines with multiple function calls, e.g.

std::cout << "Hello world! its me thread " << tid << std::endl;


While this looks like one call via operator overloading, it is actually 
three. I am not sure about how to do this atomically in C++, as I have 
never done concurrent programming using command-line interfaces. All of 
mine is in the GUI, where things are a bit different in terms of I/O.

-- 
John Gaughan
http://www.jtgprogramming.org/

Reply via email to