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

« back to all changes in this revision

Viewing changes to yo/stl/threading.yo

  • 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
1
The C++11 standard adds i(multi threading) to bf(C++) through the bf(C++)
2
2
standard library.
3
3
 
4
 
label(PTHREADS)
5
 
The annotations() don't discuss the concepts behind multi threading. It is a
6
 
topic by itself and many good reference sources exist (cf.  i(Nichols, B),
7
 
em(et al.)'s
 
4
label(PTHREADS) The annotations() do not cover the concepts behind multi
 
5
threading. It is assumed that the reader has a basic knowledge of these
 
6
concepts. Multi threading is a topic by itself and many good reference sources
 
7
exist (cf.  i(Nichols, B), em(et al.)'s
8
8
        url(Pthreads Programming)(http://oreilly.com/catalog/), O'Reilly
9
9
        hi(Pthreads Programming)hi(http://oreilly.com/catalog/)
10
10
    for some good introductions to multi-threading).
11
11
 
12
 
Multi threading facilities are offered by the class hi(thread)
13
 
tt(std::thread). Its constructor and assignment operator accept a function or
14
 
function object that handles the thread created by the tt(thread) object.
15
 
 
16
 
Thread synchronization is handled by objects of the class hi(mutex)
17
 
tt(std::mutex) and hi(condition variable) condition variables are implemented
18
 
by the class hi(condition_variable) tt(std::condition_variable).
19
 
 
20
 
In order to use multi threading in bf(C++) programs the Gnu tt(g++) compiler
21
 
requires the use of the tt(-pthread)
 
12
Multi threading facilities are offered by the class tt(std::thread). 
 
13
 
 
14
Thread synchronization is realized using objects of the class tt(std::mutex)
 
15
and em(condition variables) are implemented by the class
 
16
tt(std::condition_variable).
 
17
 
 
18
Members of these classes may throw tt(system_error) objects (cf. section
 
19
ref(SYSTEMERROR)) when encountering a low-level error condition.
 
20
 
 
21
In order to hi(multi threading: using g++) use multi threading in bf(C++)
 
22
programs the Gnu tt(g++) compiler requires the use of the tt(-pthread)
22
23
        hi(compiler flag: -pthread)hi(multi threading: -pthread)
23
24
 flag. E.g., to compile a multi-threaded program defined in a source file
24
25
tt(multi.cc) the compiler must be called as follows:
26
27
    g++ --std=c++0x -pthread -Wall multi.cc
27
28
        )
28
29
 
29
 
Threads in bf(C++) are very much under development. It is likely that in the
30
 
near future features will be added and possibly redefined. The next sections
31
 
should therefore be read with this in mind.
32
30
 
33
31
COMMENT(
34
32
 
 
33
 
35
34
What if you don't want to share your data? What if you want exactly the
36
35
opposite: For each thread to have its own copy? This is the scenario addressed
37
36
by the new thread_local storage duration keyword.