Boost logo

Boost Users :

Subject: [Boost-users] Several novice questions concerning threading
From: Master (master.huricane_at_[hidden])
Date: 2012-04-11 07:31:57


Hello all .
i am a newbie to the boost community . i recently started learning about
threads in boost . now there are some questions i would like to ask :
1.where can i find examples showing practical uses of boost::thread
features?
2.how can i get all threads ID issued by me in my app?
3.how can i iterate through running threads in my app ?
4.is there any kind of means to get all the running threads using boost
library? if it does whats the calss? if it doesnt how can i do that?
5.can i resume a thread after pausing it ? ( how can i pause a thread? )
6. how can i share a variable between two or more threads , suppose i have
a loop , i want two threads to simultaneously iterate through it , if
thread1 counted to 3, thread2 continues it from 4 and so on . ?
i already tried
------

> what is wrong with my sample app ?
> #include <iostream>
> #include <boost/thread.hpp>
> using namespace std;
> using namespace boost;
>
> mutex bmutex;
> int i=0;
> int sum=0;
> void IteratorFunc(int threadid)
> {
> for ( ; i<25 ; i++)
> {
> lock_guard<mutex> locker(bmutex);
>
> cout<<"\t"<<threadid<<"\t"<<this_thread::get_id()<<"\t"<<i<<"\n";
> sum+=i;
> }
> }
>
> int main()
> {
> //boost::posix_time::ptime start =
> boost::posix_time::microsec_clock::local_time();
>
> thread thrd(IteratorFunc,1);
> thread thrd2(IteratorFunc,2);
>
> cout<<sum;
> thrd.join();
> thrd2.join();
> }
>
Thank you in advance



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net