Boost logo

Threads-Devel :

Subject: [Threads-devel] On Linux boost threads are listed as processes
From: Neetu Garg (garg_neetu_at_[hidden])
Date: 2010-02-26 14:37:06


Hi,

I have one very basic question. I am new to linux/Unix environment. I have very basic multithreaded program based on boost thread library(program pasted in end):

In Windows Env:
* compiled and linked program statically
* Ran the program and saw just one process in "task manger"

In Linux Env
* compiled and linked program statically
* Ran the program and saw 10 processes(I created 10 threads in my program) listed when I did "ps -e".

I am not sure how I am end up creating 10 process.

Appreciate you help.

#include <boost/thread.hpp>
#include <boost/thread/barrier.hpp>
#include <boost/bind.hpp>
#include <iostream>
#include <string>
#include <boost/thread/xtime.hpp>

void printmsg(int i, ::boost::barrier *b)
{
        boost::xtime xt;
        boost::xtime_get(&xt, boost::TIME_UTC);
        xt.sec += 60;
        boost::thread::sleep(xt); // Sleep for 60 second
        std::cout << "I am thread num :" << i << "\n";
        (*b).wait();

}

int main()
{
        using ::boost::thread;
        using ::boost::bind;
        ::boost::barrier serThreadBar(10);
        boost::thread_group nodeThreadGrp;
        for(int i=0; i<10; i++)
        {
                nodeThreadGrp.create_thread(bind( printmsg, i, &serThreadBar));
        }
        nodeThreadGrp.join_all();
        std::cout << "DONE";
        getchar();
        return 0;
}

Regards,
NG

      


Threads-Devel list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk