~ubuntu-branches/ubuntu/trusty/c++-annotations/trusty-proposed

« back to all changes in this revision

Viewing changes to yo/stl/examples/threads2.cc

  • Committer: Package Import Robot
  • Author(s): Frank B. Brokken
  • Date: 2013-05-30 13:32:18 UTC
  • mfrom: (1.1.24)
  • Revision ID: package-import@ubuntu.com-20130530133218-k39mr5uredd093jr
Tags: 9.7.2-1
New upstream release, repairs several minor left-over flaws.
This release incorporates 9.7.0 and 9.7.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
    #include <thread>
 
2
    #include <iostream>
 
3
    #include <unistd.h>
 
4
 
 
5
    using namespace std;
 
6
 
 
7
    // do not forget to use -lpthread with g++
 
8
 
 
9
    void fun(size_t count, char const *txt)
 
10
    {
 
11
 
 
12
        for (; count--; )
 
13
            cout << count << ": " << txt << endl;
 
14
    }
 
15
 
 
16
    int main()
 
17
    {                   // runs the threads following
 
18
                        // the object construction
 
19
        thread display(fun, 3, "hello world");
 
20
        display.detach();
 
21
 
 
22
        thread second(fun, 3, "a second thread");
 
23
        second.detach();
 
24
 
 
25
        cout << "leaving" << endl;
 
26
    }