Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Lololol SendMessage

Sign in to follow this  
Evil Steve


I had a pannic attack on the train this morning because I thought my socket code was borked again. It turns out that it's because I was logging fro several threads at once. I had a nice critical section to stop the output getting corrupted, but I was using SendMessage() to send a log message to the server window. The problem with that is, if you SendMessage() to a different thread, Windows will block the current thread until the thread that owns the window wakes up and processes the message.
The problem is, the main thread is waiting on a mutex, which is held by the thread that's logging. And the thread that's doing the logging at the moment is locked in SendMessage() waiting for the main thread to wake up. *scream*

So I got around to making a simple Log class, that lets me do things nicely. When I log something to the window now, I allocate a buffer (from a free list, to help performance and fragmentation), copy the text into it, and use PostMessage() to post it to the log window. The log window adds the text and then frees the buffer.
It also allows me to add more functions like Log::Format(), Log::System(), Log::ToFile(), and so on without any extra hastle. Yay.

As far as I can tell, the socket code is working. I still haven't got the threads sorted yet, and I still haven't posted about that either. I'll have a think about it on the train on the way home, and if I can't think of anything, I'll try posting about it.

End of lunch, back to work...
Sign in to follow this  


Recommended Comments

There are no comments to display.

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
  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!