How to crash Win2k with CreateToolhelp32Snapshot

posted in DruinkJournal
Published March 29, 2005
Advertisement
I was working on a custom assert() statement for my MUD server, and I thought I should test it out. My server has 4 threads running, although they're usually all blocked, except for the main one. Using the default assert() causes the threadthat hit the assert to pause until you dismiss the dialog box, while the other threads carry on working. That could cause some rather nasty bugs, so I decided "Hey, why not enumerate all the threads, and call SuspendThread()?". Excelent, CreateToolhelp32Snapshot() can be set to enumerate all the threads, and I can use OpenThread() on the returned ID.
One problem. I didn't read the docs. So, to save you the trouble, let me post an excerpt:
Quote:TH32CS_SNAPTHREAD: Includes all threads in the system in the snapshot. To enumerate the threads, see Thread32First.
To identify the threads that belong to a specific process, compare its process identifier to the th32OwnerProcessID member of the THREADENTRY32 structure when enumerating the threads.

Well, I figured that since the function takes a process ID, it'd enumerate all threads in the process, right? Wrong. My assert() got hit, and immediately suspended all the threads on the machine. Including winamp, MSN, firefox, DruinkIM, and MSVC. Excelent.
Well at least it worked. It did stop the other 3 threads, although the message box didn't show up because explorer was dead. However, I have it working perfectly well just now, which is great. I can assert() away as much as I want.

Oh yeah, I forgot to mention that the image in the previous journal entry doesn't match the caption, since the image was rubbish, and I got a new one. I finished the plugin and released a new update of DruinkIM which includes it. I also got rid of D3DX, since GDI+ can load all sane file formats, and it made my DLL 536kb instead of 112Kb. Which was a rather large increase IMO...
Previous Entry TEH DOEN
0 likes 1 comments

Comments

mattd
Ohhh yeah, hardcore Win32 threading.
March 30, 2005 03:19 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement