Sign in to follow this  
MARS_999

FIle access when multithreaded

Recommended Posts

I am assuming this, but logically you would need to block or use a mutex? when running multiple threads to access a single file stream?

So is there anyway to do this without much headache?

As of now I am about to store all my error messages in a vector for each thread and in the main thread just grab each objects vector of messages...

Not sure if the std lib has anything to work with files and multithreaded situations.

Thanks!

Share this post


Link to post
Share on other sites
I don't think even C++11, which is at least aware of multi-threading, would attempt to deal with this situation.

So, yes, you would have to write a function which locked a mutex, wrote out the data and then unlocked it again, which isn't really a great pain, assuming you already have a central logging system, as it would just be one or two extra lines in it to lock/unlock.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this