• Advertisement
Sign in to follow this  

FIle access when multithreaded

This topic is 2322 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement