🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Lololol SendMessage

posted in DruinkJournal
Published June 29, 2006
Advertisement
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...
Previous Entry Nearly...
Next Entry Kitties!
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement