I am writing a multi-threaded application that combines networking and irrlicht. I understand that certain things need to thread safe. I want to use iostream and fstream from C++ STL compiling under Visual Studios 2010 Express using the MSVC compiler. I have gone to http://msdn.microsoft.com/en-us/library/c9ceah3b.aspx which says that...
The iostream classes follow the same rules as the other classes, with one exception. It is safe to write to an object from multiple threads.
Now it does not say anything about fstream therefore I understand it needs to be thread safe. Should I trust Microsoft and believe that iostream is thread safe? Portability is a big deal with networking and I only want the best for my beloved Irrlicht. So should I write a lockout class with some type of a buffer to prevent all reads and writes of iostream and fstream variables together or just for fstream?
Also what is the best implementation for good performance. I am writing a server-client program using TCP/IP as a connection. I want the server to be fast so clients can send alot of data to it. Anyone know a good read?
whole quote:
[quote]The iostream classes follow the same rules as the other classes, with one exception. It is safe to write to an object from multiple threads. For example, thread 1 can write to cout at the same time as thread 2. However, this can result in the output from the two threads being intermixed.
quote]
if i understand it right it is safe to write but your result is not safe
so it is not thread safe
for example:
thread 1 writes: Im thread 1
thread 1 writes: Im thread 2
the result can be: Im thIm thread 2read 1
alternativ you can use irrNetLite 2 somewhere in the project announcements forum
it is very good in my opinion
Yes I did find this to be the case so I restructured my program so the console thread was the only thread allowed to use cout and then had all the worker threads right there own log file if they needed to express a saying. I also used a Mutex whenever I needed to access data between threads. It ended up working great.
I knew of irrnet lite but I believed it to lack functionality so I decided to go with a functional C approach. I may wrap the code into a C++ style class like irrnet lite, maybe I should release the code to compare side by side later on.