Boost logo

Boost :

From: Roland (roland.schwarz_at_[hidden])
Date: 2004-01-14 07:08:02


The thread local storage leaks memory on Windows/MSVC6.

Is this a know issue?

Small example (the tss.cpp example amended by leak debugging functions):

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

#include <boost/thread/thread.hpp>
#include <boost/thread/tss.hpp>
#include <cassert>

boost::thread_specific_ptr<int> value;

void increment()
{
    int* p = value.get();
    ++*p;
}

void thread_proc()
{
    value.reset(new int(0)); // initialize the thread's storage
    for (int i=0; i<10; ++i)
    {
        increment();
        int* p = value.get();
        assert(*p == i+1);
    }
}

int main(int argc, char* argv[])
{
        _CrtDumpMemoryLeaks();

    boost::thread_group threads;
    for (int i=0; i<5; ++i)
        threads.create_thread(&thread_proc);
    threads.join_all();
}

Debug output window:

Detected memory leaks!
Dumping objects ->
{51} normal block at 0x002F42D8, 20 bytes long.
 Data: < B/ ,/ B/ > D8 42 2F 00 88 2C 2F 00 D8 42 2F 00 CD CD CD CD
{50} normal block at 0x002F2C88, 20 bytes long.
 Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 CD CD CD CD
{45} normal block at 0x002F4178, 33 bytes long.
 Data: < C > 00 43 00 CD CD CD CD CD CD CD CD CD CD CD CD CD
{44} normal block at 0x002F4110, 40 bytes long.
 Data: < |L > 14 7C 4C 10 16 00 00 00 00 00 00 00 00 00 00 00
Object dump complete.

Regards,
Roland


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk