[Gc] libgc and std::thread (gcc 4.8/Linux/Debian) in C++11 and GC_register_my_thread

Basile Starynkevitch basile at starynkevitch.net
Thu Sep 19 04:59:13 PDT 2013


Hello all,

I'm using GCC 4.8.1 with C++11 (so compiling with g++-4.8 -std=c++11) on Debian/Sid/x86-64

I am using std::thread and I want to have the Boehm collector also collect from inside these threads.

The package versions are (as reported by dpkg -l)

libc-dev-bin                2.17-92+b1         amd64              Embedded GNU C Library: Development binaries
g++-4.8                     4.8.1-10           amd64              GNU C++ compiler
libgc-dev:amd64             1:7.2d-5           amd64              conservative garbage collector for C (development)
libstdc++-4.8-dev:amd64     4.8.1-10           amd64              GNU Standard C++ Library v3 (development files)

I was thinking that to use std::thread I had to explicitly register these threads, 
because Boehm's GC won't know them (AFAIK, Boehm is overwriting the names of 
some pthread functions), so I am coding (with -DGC_THREADS as preprocessor flag)

void do_work(int i)
{
  usleep (i*1000); 
  struct GC_stack_base sb;
  memset (&sb, 0, sizeof(sb));
  std::clog << "registering GC for thread #" << i << std::endl;
  GC_get_stack_base(&sb);
  GC_register_my_thread (&sb);
  // etc... some GC may happen here
  GC_unregister_my_thread();
}

and my main function does

   std::vector<std::thread> workers;
   workers.resize(5);
   for (int ix=1; ix<=4; ix++) 
     workers[ix] = std::thread(do_work, ix);
 
But at runtime I'm getting an abort with
 registering GC for thread #1
 Threads explicit registering is not previously enabled

Can I avoid GC_register_my_thread in my situation? 
How should I code for std::thread using libgc?

Regards.
-- 
Basile STARYNKEVITCH         https://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***


More information about the Gc mailing list