Jump to content
  • Advertisement
Sign in to follow this  
fathom88

Writing To Files and Mutexes?

This topic is 3647 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

Do you always need a mutex when writing to a file? I have a logging class which writes out to a file (a log file). Do I need to put a mutex around the place I write to the file? Mutex.Lock; fputs(Buf, mLog); fflush(mLog); Mutext.Unlock; Each Log class writes out its own file. I originally did not include a mutex. Different threads may write to the same log file but they end using the same instance of the log class. CLogger TrackLog("Plot.txt"); CLogger ErrorLog("Error.txt"); Thread A TrackLog.WriteItOut("X = 45 Y = 34"); Thread B TrackLog.WriteItOut("X = 12 Y = 14"); Does the class act as an artificial locking mechanism? Or should I go ahead and always place a mutex on the file.

Share this post


Link to post
Share on other sites
Advertisement
It's implementation dependent. Check your compiler's documentation to make sure a certain function is or isn't thread-safe.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!