Boost logo

Boost :

From: Tim Laplaca (tlaplaca_at_[hidden])
Date: 2004-11-29 09:28:53

Thanks for the link.

I'm not sure it applies though; the prog isn't spawning the threads
simultaneously, so it shouldn't be taking many resources. I've found
that even if I only have one thread spawned at one time (where the
previous thread has died out before the new one is spawned) it still
aborts at the same place.

Over the holiday I pared my program down to just the thread spawning,
and on my Mandrake setup at home it dies at the nice even (computer)
number of 256 threads. The same pared-down prog dies on my work Fedora
Core 3 machine at 405. Under Windows, it doesn't ever seem to die.

I'm getting pretty convinced this is a bug in the boost library that
manifests itself only under Linux, and not my code. Perhaps resources
are not being properly released when the threads are dying out.

Since the prog is pretty small, I'll include it here. It spawns a
thread every second, and each thread only last one second.

#include <iostream>
#include <string>
#include <stdlib.h>

// for multithreading
#include <boost/thread/mutex.hpp>
#include <boost/thread.hpp>
#include <boost/thread/xtime.hpp>
#include <boost/bind.hpp>

int totalthreads = 0;

boost::mutex io_mutex; // iostreams
boost::mutex numthreads_mutex; // for changing value of numthreads
boost::mutex threadid_mutex; // for manipulating thread_id

using namespace std;

void threadfunc()
       // wait some secs
       boost::xtime xt;
       boost::xtime_get(&xt, boost::TIME_UTC);
       xt.sec += 1;

       boost::mutex::scoped_lock scoped_lock(io_mutex);
       std::cout << " Thread Exiting. " << std::endl;

 boost::thread_group thrds;
 boost::xtime xt;

 int maxthreads=99999;

 // ********************************
 // Main thread-spawning loop
 for (int i=0; i<=maxthreads; i++)
          boost::mutex::scoped_lock scoped_lock(io_mutex);
          std::cout << "MAIN: Thread:" << totalthreads << " being
spawned... "
                   << std::endl;

          thrds.create_thread( &threadfunc);

          // wait some seconds
            boost::xtime_get(&xt, boost::TIME_UTC);
             xt.sec += 1;

     } // end thread-spawning for loop

 std::cout << "Done." << std::endl;

Here's the Makefile I build it with:

lib = /usr/local/lib/

threadtest : threadtest.o
        g++ $(lib) $(lib2) -o threadtest threadtest.o -ldl -lc -lpthread

threadtest.o : threadtest.cpp
        g++ -Wall threadtest.cpp -I/usr/local/include/boost-1_32
-pthread -c -w -O -o threadtest.o

-----Original Message-----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of Alexander Nasonov
Sent: Friday, November 26, 2004 2:07 PM
To: boost_at_[hidden]
Subject: Re: [boost] Thread: Why is my prog aborting after 283 or so

Tim Laplaca wrote:
> I wrote a prog that spawns threads (RED HAT Fedora Core 2), and after
> spawning 283 or so threads, it stops running and 'Aborted' is printed.

Take a look at:
and check your sizes.

Alexander Nasonov
Unsubscribe & other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at