The first thing I discovered when trying to get threads working is
that the -mthreads option was not being used in jam. I added the
following to the gcc-tools.jam file. I'm not totally sure it's right
-- it's needed for mingw32, but I don't know if it is necessary for
cygwin.
if $(NT)
{
flags gcc CFLAGS <threading>multi : -mthreads ;
flags gcc LINKFLAGS <threading>multi : -mthreads ;
}
Adding that let's gdb actually work on it... It doesn't crash deep in
the bowels of thread exiting in some kernel library routine. Although
it still crashes in on_thread_exit doing handlers->push_front(func).
Actually, it crashes in some STL stuff, but that's I'm not sure why,
I'm not that good with gdb yet.
After digging through the implementation of threadmon.cpp, I realized
that (unless I missed something) on_thread_exit was always called with
the same argument, which is the address of cleanup in tss.cpp.
Therefore all of the stuff in threadmon.cpp for keeping a list of
functions registered with on_thread exit were not really needed, it
would always have a list of the same pointer. So why not just keep
that pointer and call it on thread exit. I also discovered that
DllMain wasn't getting called at all because it wasn't defined as
extern "C". This drastically simplifies threadmon.cpp:
// threadmon.cpp : Defines the entry point for the DLL application.
//
#define BOOST_THREADMON_EXPORTS
#include "threadmon.hpp"
#ifdef BOOST_HAS_WINTHREADS
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from
Windows headers
#include