__debugbreak hangs on background thread

391 Views Asked by At

I'm trying to debug gnarly threading issue (in C++ code on Windows) that takes millions of runs to reproduce. "printf debugging" is not giving me enough information so I'd like to break into the debugger at the first point I detect an issue.

I've been using __debugbreak() to do this, but when that is invoked on a background thread and the debugger is not already attached it hangs. While it is hung I can attach the debugger and I'll see one of the threads is blocking on that call.

This seems to be a viable workaround, but I'd like to be sure that this is the expected behaviour. I can't seem to find any reference to it while googling, which makes me suspicious that I'm overlooking something.

Anyone know the chapter and verse on this?

[update] Actually whether I see the dialog or not seems pretty random. Worse, just as random - but independently - the __debugbreak() does not block the thread and the process has exited before I can attach the process (whether manually or from the debug dialog)).

0

There are 0 best solutions below