Boost logo

Boost Users :

From: David A. Greene (greened_at_[hidden])
Date: 2006-01-27 21:40:38

The following single-file testcase fails to link:

#include <boost/thread/thread.hpp>
#include <boost/thread/recursive_mutex.hpp>

#include <iostream>

template<typename Type>
class singleton {
   typedef boost::recursive_mutex mutex_type;
   typedef Type * handle;

   typedef mutex_type::scoped_lock lock_type;

   static mutex_type mutex;

   static handle inst;

   static Type &instance(void) {
     lock_type lock(mutex);

     if (!inst) {
       inst = new Type;

class tester {
   void test(void) { std::cerr << "Test" << std::endl; };

template<> singleton<tester>::mutex_type singleton<tester>::mutex;
template<> singleton<tester>::handle singleton<tester>::inst = 0;

int main(void)


thread.o: In function
undefined reference to `singleton<tester>::mutex'
collect2: ld returned 1 exit status

I was getting undefined references to "inst" before I added the
initializer. Is this a new adherance to the standard by g++ 4.0.2?
I didn't used to have to add the initializer to get it to link.

This is troublesome with boost::recursive_mutex because it is
noncopyable. How do I specify an initializer for it? Is it
just not possible to have a mutex static member?


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at