Home » Community » Forums » » Simple STL Logging System
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Simple STL Logging System
Post Reply 
Awesome. Was /just/ starting to think about adding this functionality into my library. Thanks for saving me the trouble of sorting this all out! :)

 User Rating: 1454   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Liked it, but why not hack the scoped_lock within the write function itself? Then you don't have issues with forgetting to lock/unlock and you still get thread safety...

 User Rating: 1654   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Quote:
Original post by visage
Liked it, but why not hack the scoped_lock within the write function itself? Then you don't have issues with forgetting to lock/unlock and you still get thread safety...
No you don't. The problem is that the ostream has an internal buffer which it uses until flush() is called (e.g. until std::endl is written) and that buffer can get overwritten by multiple threads before you even get into the write method.

I've fixed it in my own code by wrapping my osteam object in a thread-local container (using boost::thread_specific_ptr). Perhaps I should post the code I used...

 User Rating: 1645   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Interesting -- definitely overlooked that point. Thanks for clarifying. I still think it is a bit intrusive...

 User Rating: 1654   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Yes I ran into that problem with the buffering resulting in having to lock the mutex outside the calls. If someone (I saw mentioned above) has code that works, please post. I would be interested to see how it was done

 User Rating: 1025   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: