I recently implemented a utility to write user-mode dumps using MiniDumpWriteDump (part of the Debug Help Library). The implementation is separated into its own process. A target process can launch this utility and communicate with it to trigger writing a minidump.
This is all working as expected. I am not sure, though, how to interpret the rules with respect to concurrency for MiniDumpWriteDump:
All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function.
Does the above refer to calls from different threads to a single process? Or do concurrent calls also require synchronization, if MiniDumpWriteDump
is called in different processes (e.g. when each target process launches its own utility process)?
The problem is in the library: "All
DbgHelp
functions, such as this one, are single threaded".Therefore, any process invoking this library will have to make sure that only one single thread is using the
DbgHelp
functions simultaneously.Just use a lock before you use
DbgHelp
, that is, if your program usingDbgHelp
is multi-threaded (otherwise there's no problem).Another way to remove this limitation is to add a (per-thread)
context
to theDbgHelp
library: you move all (file-scope)static
and (program-scope)global
variables in a C structure passed as an argument to all library function calls.