mirror of
https://github.com/boostorg/thread.git
synced 2026-02-03 09:42:16 +00:00
Compare commits
1534 Commits
svn-branch
...
fix/10967_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2891aff469 | ||
|
|
c16ec42941 | ||
|
|
b77eac3e37 | ||
|
|
eb14d3d958 | ||
|
|
2c028aa014 | ||
|
|
ab026e239c | ||
|
|
3a48148462 | ||
|
|
9b9590730f | ||
|
|
8edc37930b | ||
|
|
ef48908f35 | ||
|
|
28ead512c1 | ||
|
|
6b60943f3e | ||
|
|
1fcaa47efa | ||
|
|
aac441392a | ||
|
|
6a34fc9c33 | ||
|
|
69d01b9bfd | ||
|
|
7b91ce7b64 | ||
|
|
978884ff0d | ||
|
|
ac8ca6eb04 | ||
|
|
1c16c52fe6 | ||
|
|
9299d26acf | ||
|
|
5577128bd8 | ||
|
|
e62c576944 | ||
|
|
ce8049f83f | ||
|
|
035217985c | ||
|
|
dfe95b3f2c | ||
|
|
e98447f974 | ||
|
|
deffa9aaf7 | ||
|
|
b87d26a900 | ||
|
|
6c9115fe39 | ||
|
|
b5b25eab1c | ||
|
|
803ba458ce | ||
|
|
c0470893d4 | ||
|
|
b2c445a030 | ||
|
|
6e37c55221 | ||
|
|
e1039e61f3 | ||
|
|
063b59e511 | ||
|
|
a342d1ccee | ||
|
|
811f3df98d | ||
|
|
8e1be55c6d | ||
|
|
421469686d | ||
|
|
72dfa02269 | ||
|
|
4c48b2276c | ||
|
|
8c7275cb9e | ||
|
|
14c5cff2ee | ||
|
|
83f38ea52c | ||
|
|
06a9f9ab6d | ||
|
|
e7f140cab6 | ||
|
|
1b99fe5587 | ||
|
|
b9a70f7aca | ||
|
|
ca87cbf57b | ||
|
|
929dc55a5a | ||
|
|
b29d9f850c | ||
|
|
1c81d8a4b1 | ||
|
|
7de29f4d45 | ||
|
|
9b0705cb6f | ||
|
|
3abdb869df | ||
|
|
f90e76a59c | ||
|
|
d4c8185cc9 | ||
|
|
e6501b5485 | ||
|
|
1ae3cb65f7 | ||
|
|
a8ad389bdd | ||
|
|
69c1d40750 | ||
|
|
58698f44f1 | ||
|
|
37afdd2e9a | ||
|
|
c87b24923a | ||
|
|
1210fc4859 | ||
|
|
d8b6ae6266 | ||
|
|
04e2223d5e | ||
|
|
579748e7a0 | ||
|
|
41c3914aaf | ||
|
|
8693eec4a4 | ||
|
|
3f699750a8 | ||
|
|
4f8243cf59 | ||
|
|
4f01891da7 | ||
|
|
efab5af918 | ||
|
|
4d03b410a8 | ||
|
|
c1925df81c | ||
|
|
cbf9fe8a5c | ||
|
|
6fd7dc0d94 | ||
|
|
a2f2924298 | ||
|
|
49d485f1aa | ||
|
|
d7251f223e | ||
|
|
20a6ef7de8 | ||
|
|
d5c41e4c4a | ||
|
|
b96b9904b7 | ||
|
|
304240b206 | ||
|
|
c61c139933 | ||
|
|
c3b98129e4 | ||
|
|
3891eeef52 | ||
|
|
f1370b1255 | ||
|
|
69f2a1df72 | ||
|
|
700301e382 | ||
|
|
952aa44a98 | ||
|
|
5fb51a74fe | ||
|
|
02bb6abef4 | ||
|
|
1a4bd71616 | ||
|
|
63dd439992 | ||
|
|
1029fa9c59 | ||
|
|
3e28ea806c | ||
|
|
07dc40a9ff | ||
|
|
6f91af2154 | ||
|
|
c3cff80557 | ||
|
|
729c8b63bb | ||
|
|
6fe7f44ea0 | ||
|
|
8fd4755e79 | ||
|
|
02b007a20e | ||
|
|
c0c78e87fc | ||
|
|
58cde5af05 | ||
|
|
c1f2c8a1f1 | ||
|
|
bacf5b52ec | ||
|
|
3babf7966e | ||
|
|
f3de7bf10f | ||
|
|
90154217cf | ||
|
|
ac0b2f9ba7 | ||
|
|
da739e680a | ||
|
|
b240b097c7 | ||
|
|
debe2fb0d1 | ||
|
|
b264ec8fc0 | ||
|
|
372f8fe10f | ||
|
|
e3c240df0a | ||
|
|
748ea5164e | ||
|
|
b44627f97d | ||
|
|
c8cd7d1d08 | ||
|
|
f0d0c0551b | ||
|
|
bb72eadbd8 | ||
|
|
f52f32afda | ||
|
|
b973e9b32e | ||
|
|
1ffef9ed2d | ||
|
|
f24ea524bd | ||
|
|
4111471ba5 | ||
|
|
5e970b987e | ||
|
|
c7b5729cf3 | ||
|
|
291ebded8e | ||
|
|
0c2c8ed3b8 | ||
|
|
5294dfa149 | ||
|
|
7f5dfb633d | ||
|
|
f381a7d591 | ||
|
|
aceabda609 | ||
|
|
dc4b619b57 | ||
|
|
abb3fc97e0 | ||
|
|
ec6ae7b9b4 | ||
|
|
8c5ba97d39 | ||
|
|
617b979214 | ||
|
|
96667cfcce | ||
|
|
a981650ce9 | ||
|
|
00b25853b2 | ||
|
|
ef04ce8bce | ||
|
|
5091ad705f | ||
|
|
b77f802c47 | ||
|
|
da945436c1 | ||
|
|
27befdf26f | ||
|
|
f73007910a | ||
|
|
8c3cfacf06 | ||
|
|
7d4392e157 | ||
|
|
aff3f424a9 | ||
|
|
546ca909c4 | ||
|
|
7dac51706c | ||
|
|
5ee0e27b5a | ||
|
|
b4fd7fdeb1 | ||
|
|
c75ea7db89 | ||
|
|
19294dc756 | ||
|
|
52a360775e | ||
|
|
c632b75db1 | ||
|
|
11e4c950ac | ||
|
|
8440e9a7d8 | ||
|
|
02bc292c20 | ||
|
|
6d68bac44b | ||
|
|
5d0d128cab | ||
|
|
ec542d3c8b | ||
|
|
6e3216643b | ||
|
|
016f5653cf | ||
|
|
ce46539183 | ||
|
|
e93035ce42 | ||
|
|
53a46593a8 | ||
|
|
c2426b8fad | ||
|
|
7d841f6337 | ||
|
|
556bbde8a7 | ||
|
|
a0c1462a6a | ||
|
|
234df13faf | ||
|
|
24983f0bce | ||
|
|
722997379b | ||
|
|
f36f5d6dbb | ||
|
|
9ee1044f92 | ||
|
|
ebeb36646c | ||
|
|
8ebf0e7f21 | ||
|
|
0dc2f69bc1 | ||
|
|
c3b549d947 | ||
|
|
6552cf64b5 | ||
|
|
d5f335b8a4 | ||
|
|
80591fb64d | ||
|
|
0543b522cb | ||
|
|
3dbc5d0664 | ||
|
|
2d0272345b | ||
|
|
f1a274b51c | ||
|
|
b7f1706ab8 | ||
|
|
f299fb8083 | ||
|
|
074dcbcbf5 | ||
|
|
af6f80a3c7 | ||
|
|
957253401f | ||
|
|
3195253230 | ||
|
|
4336a7bbe3 | ||
|
|
3b75d6dabc | ||
|
|
fc0d7e23b3 | ||
|
|
aeabda8d45 | ||
|
|
3bde7e103c | ||
|
|
ea0889485e | ||
|
|
d4d46c64dd | ||
|
|
f3fa80c866 | ||
|
|
7e21f24991 | ||
|
|
2037a64c51 | ||
|
|
8bfd1cea31 | ||
|
|
a26e7eb8c4 | ||
|
|
e47eba8751 | ||
|
|
8aef8000d9 | ||
|
|
0b2a61bca0 | ||
|
|
78f1044c68 | ||
|
|
26042ca26a | ||
|
|
74132067ba | ||
|
|
c4d42e6b6c | ||
|
|
59c504d5d8 | ||
|
|
b81a838a43 | ||
|
|
c6e70226ea | ||
|
|
5cdd807718 | ||
|
|
2a6948d74d | ||
|
|
a06dde3794 | ||
|
|
726a3faf19 | ||
|
|
590a3d99b0 | ||
|
|
c977c8d420 | ||
|
|
a1faacd7bb | ||
|
|
866b78cbd0 | ||
|
|
0861f81b05 | ||
|
|
6488028a22 | ||
|
|
14dfe49c50 | ||
|
|
08c4599fb6 | ||
|
|
ca14e6187d | ||
|
|
f263c6014e | ||
|
|
9e962e12e2 | ||
|
|
6e154d45a4 | ||
|
|
c54e519f72 | ||
|
|
5c61dced5e | ||
|
|
8a7f927be9 | ||
|
|
6074487b73 | ||
|
|
04c53415fd | ||
|
|
fe6daec2bc | ||
|
|
f75b2ca155 | ||
|
|
68be44ec06 | ||
|
|
817591b87c | ||
|
|
d7a3f124db | ||
|
|
c6817aeb1c | ||
|
|
9ceea9822f | ||
|
|
c266790b8d | ||
|
|
00ad9dddb9 | ||
|
|
21617e1acb | ||
|
|
99ac322223 | ||
|
|
414fce4580 | ||
|
|
fe195e776b | ||
|
|
8a6d3d68ce | ||
|
|
3a5c926930 | ||
|
|
685ee1506a | ||
|
|
2062cebb54 | ||
|
|
126030eb8c | ||
|
|
ac1b9653f3 | ||
|
|
54ee07e745 | ||
|
|
ca298c2c86 | ||
|
|
4def87448e | ||
|
|
5719ea9e9f | ||
|
|
6583d87c92 | ||
|
|
fcf7a1811e | ||
|
|
d8f628ae65 | ||
|
|
0bd10b7244 | ||
|
|
24635c588f | ||
|
|
4f8106c00e | ||
|
|
3c4f1ea365 | ||
|
|
b5a50ab443 | ||
|
|
cb8a4a27bb | ||
|
|
8c0640e5be | ||
|
|
f807a678e0 | ||
|
|
49a1779d7f | ||
|
|
d3d2ad2390 | ||
|
|
abf844f50e | ||
|
|
4d52ef0740 | ||
|
|
40620e3d4b | ||
|
|
c3ab21a7ba | ||
|
|
c3002edc54 | ||
|
|
100bb706d6 | ||
|
|
de6a4df3a8 | ||
|
|
9669830a86 | ||
|
|
2937171413 | ||
|
|
dd0bfdd7ce | ||
|
|
89e340b177 | ||
|
|
c744899e45 | ||
|
|
0a4af0c5ed | ||
|
|
e6eb24d4a9 | ||
|
|
0d10e282fa | ||
|
|
e8181da6d4 | ||
|
|
68dc454a66 | ||
|
|
0e0ee99c61 | ||
|
|
f747d79c5b | ||
|
|
73fbc520e8 | ||
|
|
7d4f485ade | ||
|
|
143adde27d | ||
|
|
a7400061c6 | ||
|
|
d2a65d2427 | ||
|
|
82379f83a8 | ||
|
|
cc29295986 | ||
|
|
9d1c957625 | ||
|
|
1dbf7028fe | ||
|
|
0bba5e630e | ||
|
|
84c30313a2 | ||
|
|
54646e9959 | ||
|
|
3f5823f50a | ||
|
|
e1636bdbd5 | ||
|
|
750c849b0f | ||
|
|
0a05db8399 | ||
|
|
1d7da085ea | ||
|
|
75236fe3ae | ||
|
|
80634ee51e | ||
|
|
b1ac899f23 | ||
|
|
aa37de7aad | ||
|
|
9d527bebe0 | ||
|
|
f7c18c55bb | ||
|
|
1a2197c7f9 | ||
|
|
4a54ac0331 | ||
|
|
c6593d87b0 | ||
|
|
51e49c69b5 | ||
|
|
ab2a180de5 | ||
|
|
3772a8294b | ||
|
|
155ccfffbe | ||
|
|
bfa0ccee88 | ||
|
|
980772d514 | ||
|
|
94b27db991 | ||
|
|
0a58445b63 | ||
|
|
f02e25e4e7 | ||
|
|
acb117b5a9 | ||
|
|
8682f7cb48 | ||
|
|
4503c0e1da | ||
|
|
dc3397c452 | ||
|
|
af7fde5eae | ||
|
|
36bc3c0523 | ||
|
|
0218cb90b3 | ||
|
|
f4d4c16294 | ||
|
|
85d22a8d93 | ||
|
|
7eb67443dd | ||
|
|
4308e0ec24 | ||
|
|
ac9497dec9 | ||
|
|
8fec35f444 | ||
|
|
7b3fa08503 | ||
|
|
a2e1e80343 | ||
|
|
690feeb9ba | ||
|
|
5d76ab52e7 | ||
|
|
cb845f19e4 | ||
|
|
2886e985b4 | ||
|
|
f4d0ecbab5 | ||
|
|
d187732946 | ||
|
|
1fc78c7ceb | ||
|
|
5c18d92a5f | ||
|
|
06325961ef | ||
|
|
10b283e03a | ||
|
|
6ab71dc057 | ||
|
|
47be5228b1 | ||
|
|
6c5a6e4330 | ||
|
|
326842cc7f | ||
|
|
9f592860cd | ||
|
|
4148842426 | ||
|
|
7edae6614b | ||
|
|
2554065a91 | ||
|
|
74bb7d6b29 | ||
|
|
fbfda71555 | ||
|
|
f3a66f76e0 | ||
|
|
19346e1817 | ||
|
|
5753026ceb | ||
|
|
f6edd7cace | ||
|
|
126ed2428b | ||
|
|
fd631e2794 | ||
|
|
44f9a2f4ad | ||
|
|
8665c5d510 | ||
|
|
e1d6baddd6 | ||
|
|
9287a29c9d | ||
|
|
5c0cecaaf8 | ||
|
|
713f5a449c | ||
|
|
b336427571 | ||
|
|
2a16b649ad | ||
|
|
3723cedcab | ||
|
|
3ad582222c | ||
|
|
c9a33b8668 | ||
|
|
88880770d3 | ||
|
|
9138a2ae92 | ||
|
|
d558de7811 | ||
|
|
19290fddf9 | ||
|
|
2ac967d1dc | ||
|
|
6e81db4172 | ||
|
|
3a68a63478 | ||
|
|
7875edd234 | ||
|
|
2be0b4f8fd | ||
|
|
67528fc9af | ||
|
|
4da1e9dca1 | ||
|
|
d8c9be3449 | ||
|
|
f02390a804 | ||
|
|
955b207c05 | ||
|
|
c17f5d3fc7 | ||
|
|
8685c32d18 | ||
|
|
f51e8c812a | ||
|
|
51aff0fb00 | ||
|
|
bfe7af29bc | ||
|
|
4681104b33 | ||
|
|
d602f44af6 | ||
|
|
dc55945760 | ||
|
|
f7f0347780 | ||
|
|
d6c4be0cd0 | ||
|
|
e146febd70 | ||
|
|
67ca45ed83 | ||
|
|
cad6f2b9a6 | ||
|
|
7756df2ce0 | ||
|
|
ae831efe08 | ||
|
|
fc65611e82 | ||
|
|
8c6dcb9709 | ||
|
|
67afa35c49 | ||
|
|
63d9ae2b29 | ||
|
|
08aa0d2fb6 | ||
|
|
3c8334f8c4 | ||
|
|
0e2c8ed9e3 | ||
|
|
5bfa7cff41 | ||
|
|
e3a1498355 | ||
|
|
6fab117c17 | ||
|
|
4a63d4992c | ||
|
|
04e3d918fb | ||
|
|
0073516f0a | ||
|
|
89de3dcf4f | ||
|
|
47f40f991f | ||
|
|
8b351fe473 | ||
|
|
2da4e8c29e | ||
|
|
8dce737911 | ||
|
|
24f1e620e8 | ||
|
|
ed6459ecd2 | ||
|
|
3a7f0b1e78 | ||
|
|
8f06153f46 | ||
|
|
858816b2d2 | ||
|
|
4bc70444a4 | ||
|
|
fcc027369f | ||
|
|
5c78582794 | ||
|
|
7f479a1dec | ||
|
|
4f2a7b2256 | ||
|
|
5c88e6ce61 | ||
|
|
650e374492 | ||
|
|
6319080ef2 | ||
|
|
3ac48bdd65 | ||
|
|
c3c8ada97d | ||
|
|
325d8cf5ca | ||
|
|
134c323958 | ||
|
|
fd5dd0c2ed | ||
|
|
4a83aa58ed | ||
|
|
7d96aa625c | ||
|
|
5520763a73 | ||
|
|
ad010e0647 | ||
|
|
d57a4c6565 | ||
|
|
73f5c060ca | ||
|
|
c67e39f126 | ||
|
|
5a3c301582 | ||
|
|
dc5a8a9c4e | ||
|
|
1e49343ff4 | ||
|
|
93d1855e64 | ||
|
|
a39dd7e8b3 | ||
|
|
7e5cb92bab | ||
|
|
62cf0f86f6 | ||
|
|
c12e07754a | ||
|
|
cbc4266774 | ||
|
|
3a038d33e5 | ||
|
|
51ba4be998 | ||
|
|
2d50af8481 | ||
|
|
3fb971386a | ||
|
|
e438c98070 | ||
|
|
1e2a76de47 | ||
|
|
34311a60fa | ||
|
|
794d54a65c | ||
|
|
d759dd2dba | ||
|
|
fe46155997 | ||
|
|
cacb5b19a6 | ||
|
|
30803a38b2 | ||
|
|
9fc6fec1eb | ||
|
|
29babb974e | ||
|
|
66578bf57b | ||
|
|
1da5f9563c | ||
|
|
52039f75a3 | ||
|
|
bb6fcc3b5c | ||
|
|
6225c8309a | ||
|
|
1fc1d8aedb | ||
|
|
042a86c984 | ||
|
|
364f3ea030 | ||
|
|
fe8991b7fa | ||
|
|
c87d27a06d | ||
|
|
68d7c69a4b | ||
|
|
f4fb2c1ab0 | ||
|
|
6873d85650 | ||
|
|
b59e57e4cc | ||
|
|
582649ed44 | ||
|
|
d0f9d6216a | ||
|
|
28564064ff | ||
|
|
ff9636b8e0 | ||
|
|
d83d23bee0 | ||
|
|
63f35e9f52 | ||
|
|
5ad38d52e8 | ||
|
|
9d6cd40d8d | ||
|
|
4362cd655e | ||
|
|
0c44630029 | ||
|
|
a01af79331 | ||
|
|
2df6ce78a4 | ||
|
|
74891c9836 | ||
|
|
3951871d70 | ||
|
|
9dd08547f7 | ||
|
|
c6dbb0c9a5 | ||
|
|
5a1a9df623 | ||
|
|
a6f67e25e3 | ||
|
|
b69ec54695 | ||
|
|
465aee1b66 | ||
|
|
14d3c59682 | ||
|
|
3f2d8f8865 | ||
|
|
dc8449bd0e | ||
|
|
d3a6277714 | ||
|
|
81d8944b96 | ||
|
|
54faaaf087 | ||
|
|
5a43d5ffe9 | ||
|
|
c628e51e6c | ||
|
|
0b2c57876f | ||
|
|
a66b269198 | ||
|
|
9e07202e21 | ||
|
|
ba03de1f06 | ||
|
|
9e2a34ca9d | ||
|
|
4cf80c6685 | ||
|
|
455c31c0e9 | ||
|
|
a8d5fd48c1 | ||
|
|
294a5404c2 | ||
|
|
6d01267030 | ||
|
|
1c48d237a8 | ||
|
|
11ae5c8c44 | ||
|
|
9d10bd035a | ||
|
|
100bd73f03 | ||
|
|
7b48c02d2f | ||
|
|
d8a9331464 | ||
|
|
b60968b045 | ||
|
|
da41bdb632 | ||
|
|
5fcfd0e4e8 | ||
|
|
4d2110f5e5 | ||
|
|
2d2d1112d6 | ||
|
|
7cf6934515 | ||
|
|
757327ba10 | ||
|
|
a82843d3ab | ||
|
|
5779f6676d | ||
|
|
b359424858 | ||
|
|
a5f7d92960 | ||
|
|
83167d8c15 | ||
|
|
7d2270f8c8 | ||
|
|
f87dbb83b1 | ||
|
|
1a613d03a9 | ||
|
|
d42f4ff169 | ||
|
|
ffbcf96d90 | ||
|
|
e294e6bcc8 | ||
|
|
093a329c1a | ||
|
|
f5e246ebb0 | ||
|
|
467a88c4f8 | ||
|
|
f021bad1d5 | ||
|
|
ecd97ec4ea | ||
|
|
c71882816c | ||
|
|
ef5d43fac9 | ||
|
|
13141f8ada | ||
|
|
fb5404947e | ||
|
|
64c73fac46 | ||
|
|
f24086fe89 | ||
|
|
3e64214e68 | ||
|
|
ed4f0f7b6d | ||
|
|
50c18d6274 | ||
|
|
d5cf734a21 | ||
|
|
43f0c059d3 | ||
|
|
e775ef5c27 | ||
|
|
06b7a41add | ||
|
|
22369e9d8c | ||
|
|
06d2a11127 | ||
|
|
6dd195bbc6 | ||
|
|
8a259612cd | ||
|
|
9fb88b8f47 | ||
|
|
528fcbde56 | ||
|
|
a0397315b2 | ||
|
|
44ec248340 | ||
|
|
7eba48576c | ||
|
|
677dbe7688 | ||
|
|
451027deec | ||
|
|
16b42b6c63 | ||
|
|
a543b918f0 | ||
|
|
619ddf54b9 | ||
|
|
116c947af9 | ||
|
|
a0931c117d | ||
|
|
79e1e88f2e | ||
|
|
af3b5f3227 | ||
|
|
7bebf0a062 | ||
|
|
6dad044ab7 | ||
|
|
19bd0d5eba | ||
|
|
f922fa56e4 | ||
|
|
290faf192d | ||
|
|
054bbad65a | ||
|
|
b1a674869d | ||
|
|
df7fbe085a | ||
|
|
b03cebff7b | ||
|
|
c9c46e87b5 | ||
|
|
d4e6332eca | ||
|
|
80594adcbb | ||
|
|
4ea14fb9da | ||
|
|
5a22af7639 | ||
|
|
7b157ab5f4 | ||
|
|
a73425eb00 | ||
|
|
b254afc229 | ||
|
|
a1edda3437 | ||
|
|
c784369f76 | ||
|
|
0b7462c4f2 | ||
|
|
23ff6e0120 | ||
|
|
06491889ea | ||
|
|
abf441ee63 | ||
|
|
9615a51123 | ||
|
|
a0bfa7faeb | ||
|
|
44b741e445 | ||
|
|
41d336e7fb | ||
|
|
fc177914e1 | ||
|
|
d0056e0cc8 | ||
|
|
6075cf2df6 | ||
|
|
1eacb8c71d | ||
|
|
7476f71af6 | ||
|
|
d86b5d2c0d | ||
|
|
09f86d603e | ||
|
|
ca3d7dab0b | ||
|
|
7e35a60650 | ||
|
|
2b5bd7275e | ||
|
|
ca37d07184 | ||
|
|
6f2efbcb32 | ||
|
|
1ce6a90f95 | ||
|
|
0a101e15d1 | ||
|
|
d2f7766f8a | ||
|
|
ba7a0935f2 | ||
|
|
7277a94411 | ||
|
|
197bbc1fd3 | ||
|
|
b9e2d7b13d | ||
|
|
579501d98e | ||
|
|
dc352450ca | ||
|
|
21b2bbc8ca | ||
|
|
bd9105a104 | ||
|
|
935d851cdf | ||
|
|
68142e8ff8 | ||
|
|
f9b257e368 | ||
|
|
1dad495280 | ||
|
|
fb2310b48a | ||
|
|
247e9a4f09 | ||
|
|
c1ec1ada0e | ||
|
|
d030dbd61c | ||
|
|
bebd56ee21 | ||
|
|
75586eec0e | ||
|
|
659343d287 | ||
|
|
8e63c72867 | ||
|
|
65416bb8b6 | ||
|
|
71a647b66b | ||
|
|
8416d3e8bb | ||
|
|
fc57e9dde0 | ||
|
|
4acfe0975c | ||
|
|
158e8ead50 | ||
|
|
0fc69c4d9e | ||
|
|
e314bf03ce | ||
|
|
6f2decdacf | ||
|
|
4bd3e09a0d | ||
|
|
8b89d21814 | ||
|
|
a16f508b8a | ||
|
|
1642db3441 | ||
|
|
8804ab8e73 | ||
|
|
b389079417 | ||
|
|
8f7be637b2 | ||
|
|
94c15aa0cc | ||
|
|
951c8952ff | ||
|
|
59f91a2405 | ||
|
|
f4a3d52654 | ||
|
|
517e177d7a | ||
|
|
e72184e9ee | ||
|
|
0ba92626f0 | ||
|
|
ce46c31555 | ||
|
|
73348d69d2 | ||
|
|
15eff9e412 | ||
|
|
dd70cd5b40 | ||
|
|
b290f995d0 | ||
|
|
c1dd0e1e43 | ||
|
|
e160cf0254 | ||
|
|
44a02c1f5f | ||
|
|
a0071b301b | ||
|
|
c77281f724 | ||
|
|
8a0578c93c | ||
|
|
c7dcb1daae | ||
|
|
af330fb61b | ||
|
|
ab64afa2a7 | ||
|
|
85792f9946 | ||
|
|
e0d4e63e48 | ||
|
|
67da33a182 | ||
|
|
b2bd9f4ca9 | ||
|
|
189356680b | ||
|
|
d07835908f | ||
|
|
0e0cd2c950 | ||
|
|
a849a41367 | ||
|
|
4b1c13e5cb | ||
|
|
f3777b9306 | ||
|
|
3e5e12e1ac | ||
|
|
e618900149 | ||
|
|
a50176c259 | ||
|
|
94e524a1e6 | ||
|
|
cb3259b23f | ||
|
|
ec811d3c4a | ||
|
|
bf67321336 | ||
|
|
4b71ef9354 | ||
|
|
23bf16a638 | ||
|
|
c3ada352f4 | ||
|
|
e012b8abb2 | ||
|
|
610bdc4aca | ||
|
|
6675f4645f | ||
|
|
2895bfe269 | ||
|
|
27e2d632cd | ||
|
|
8ee9ed1904 | ||
|
|
abdaa7b5b3 | ||
|
|
565a022a5a | ||
|
|
e0ed1d6d61 | ||
|
|
f8b1287153 | ||
|
|
5ed50d68f2 | ||
|
|
0f7d406b9f | ||
|
|
2f0a6c01c2 | ||
|
|
c8edd6c795 | ||
|
|
4d5474d600 | ||
|
|
2b8930a5bf | ||
|
|
7c89563108 | ||
|
|
fcb94bcecf | ||
|
|
593e9e0f2f | ||
|
|
4209dfaa7f | ||
|
|
0fac7be5b9 | ||
|
|
233484f254 | ||
|
|
0936913bf6 | ||
|
|
03ebc320f1 | ||
|
|
ea11670593 | ||
|
|
607080857b | ||
|
|
6728fdb3b1 | ||
|
|
580c1b7be4 | ||
|
|
ad3247dd29 | ||
|
|
03a43d09a4 | ||
|
|
7f043d7b07 | ||
|
|
77a8c6667f | ||
|
|
418a3f6978 | ||
|
|
6b300d2e4c | ||
|
|
50ae9d93a6 | ||
|
|
168ee37d30 | ||
|
|
81528d64d5 | ||
|
|
e6b8a133a8 | ||
|
|
047ca43b72 | ||
|
|
3c6509184a | ||
|
|
ec1ce4cf98 | ||
|
|
526478338d | ||
|
|
f49e6e8dc3 | ||
|
|
186d58eef7 | ||
|
|
d2bbc1b7c1 | ||
|
|
2a503b5c81 | ||
|
|
a25b918a67 | ||
|
|
821376f552 | ||
|
|
4387de4be8 | ||
|
|
0663b30528 | ||
|
|
37b0eb2c48 | ||
|
|
de0272abcf | ||
|
|
cfc3634108 | ||
|
|
1c62b1599d | ||
|
|
1d2ec17d52 | ||
|
|
0d9e8a0c3c | ||
|
|
9b28bb59c9 | ||
|
|
0fce559711 | ||
|
|
de191d213e | ||
|
|
ae89c307bf | ||
|
|
0dba7ba99b | ||
|
|
1b67c83359 | ||
|
|
d28465b656 | ||
|
|
bb3493bdf0 | ||
|
|
0cd8326f21 | ||
|
|
5c5c818bc5 | ||
|
|
124b99b2a4 | ||
|
|
1cabac151a | ||
|
|
df48b734a2 | ||
|
|
039d744960 | ||
|
|
004e8a4fcf | ||
|
|
d8f8acbe38 | ||
|
|
8a01f9ee09 | ||
|
|
315af061cd | ||
|
|
18491c933d | ||
|
|
d01c0232da | ||
|
|
91e32e3f02 | ||
|
|
88294f4161 | ||
|
|
9cdc23159a | ||
|
|
c95f1d95af | ||
|
|
45c87d392f | ||
|
|
1c0a4999b8 | ||
|
|
30bfc7bcea | ||
|
|
48f8c1c1c8 | ||
|
|
c47ea136b6 | ||
|
|
a3d30b2a89 | ||
|
|
11e15ff0f2 | ||
|
|
fb4b4fb14a | ||
|
|
0ede82e059 | ||
|
|
708b660c0b | ||
|
|
9f27bba490 | ||
|
|
095da2890e | ||
|
|
389d76cbc1 | ||
|
|
493cbc030c | ||
|
|
2f7b936cd6 | ||
|
|
6f3ee1eebf | ||
|
|
32f7b212bd | ||
|
|
4fcdabca90 | ||
|
|
b03de37155 | ||
|
|
73af713503 | ||
|
|
a903532cef | ||
|
|
d6178b3139 | ||
|
|
ec1241a6d8 | ||
|
|
ae819901ab | ||
|
|
3c0294cf3a | ||
|
|
0ae81b8d4c | ||
|
|
21bc767445 | ||
|
|
47b6368ef7 | ||
|
|
05f02e1476 | ||
|
|
a3098b5dfd | ||
|
|
23ea174056 | ||
|
|
bd69c9382f | ||
|
|
ce19b13c43 | ||
|
|
b47f43df59 | ||
|
|
8262d61ff5 | ||
|
|
e9217d02f0 | ||
|
|
6741c8420a | ||
|
|
fe45847841 | ||
|
|
5d13b87dd3 | ||
|
|
e1f5fbdc33 | ||
|
|
b342cf683b | ||
|
|
e94946cc8c | ||
|
|
8604ca1b85 | ||
|
|
9847f57ce7 | ||
|
|
74e2c4cbcb | ||
|
|
4d013af927 | ||
|
|
7b54159af3 | ||
|
|
16ad9c868e | ||
|
|
26f4ad3db2 | ||
|
|
715928e143 | ||
|
|
40d694e893 | ||
|
|
4d84fb97c9 | ||
|
|
ab7bb7a82d | ||
|
|
171be40a1f | ||
|
|
18d4a8a0f8 | ||
|
|
dedaa7e617 | ||
|
|
6173ae42a9 | ||
|
|
2d8852199b | ||
|
|
792604127e | ||
|
|
81d0aaf7bc | ||
|
|
26c495e5b3 | ||
|
|
a1f8717170 | ||
|
|
460a38b994 | ||
|
|
dbefae706c | ||
|
|
a33e82af60 | ||
|
|
12a1c7c71c | ||
|
|
8f283b3c2b | ||
|
|
b1ae3a98e8 | ||
|
|
fcaaa68f87 | ||
|
|
89e944914b | ||
|
|
b7622b7407 | ||
|
|
a56358c8f8 | ||
|
|
dafe4bea1a | ||
|
|
408a6cb70e | ||
|
|
97c0ddbee4 | ||
|
|
330502ea1e | ||
|
|
662118b5c6 | ||
|
|
7bc8c437ab | ||
|
|
8bee2291fd | ||
|
|
39c4db3e66 | ||
|
|
749b1034f9 | ||
|
|
735102d4a0 | ||
|
|
5e30d7486e | ||
|
|
71f864bc5c | ||
|
|
b31c1a11d5 | ||
|
|
bf03f733a6 | ||
|
|
ca04d699bc | ||
|
|
530aaaae38 | ||
|
|
36970f3240 | ||
|
|
7c97dc8131 | ||
|
|
a7336c2c5e | ||
|
|
8866935d0b | ||
|
|
4f06c2392b | ||
|
|
677113cfbe | ||
|
|
a01faf1bb8 | ||
|
|
050b43757f | ||
|
|
448c4b21b5 | ||
|
|
84d8dea5ba | ||
|
|
5fa5b680f0 | ||
|
|
5b26427079 | ||
|
|
d426d2ca88 | ||
|
|
2e5bc32b33 | ||
|
|
b0b975e8ef | ||
|
|
1f4df63577 | ||
|
|
cf7c218a65 | ||
|
|
1a1751b45d | ||
|
|
0354c2fcc3 | ||
|
|
c4420d7591 | ||
|
|
1679cd2fff | ||
|
|
32db9f2e71 | ||
|
|
6b98bee683 | ||
|
|
7de77cf13c | ||
|
|
8334f4e68a | ||
|
|
1ac7e7129d | ||
|
|
daec1268f9 | ||
|
|
6ef2dade3a | ||
|
|
c47bd34760 | ||
|
|
0d9ebfc820 | ||
|
|
c594f5d9ae | ||
|
|
3332d8df66 | ||
|
|
852c173c96 | ||
|
|
a73cf83971 | ||
|
|
bcf30f2dfc | ||
|
|
2ea1aec7fd | ||
|
|
67a5a6f39e | ||
|
|
dc5a26c5d3 | ||
|
|
3c8f164371 | ||
|
|
93c14be188 | ||
|
|
b305cc29fc | ||
|
|
c2001fb9d2 | ||
|
|
d3a8321be0 | ||
|
|
8bfd588b4c | ||
|
|
5268fd3749 | ||
|
|
19bbd85d9d | ||
|
|
deca987299 | ||
|
|
1a4eed3b69 | ||
|
|
348bd080ef | ||
|
|
1214f99227 | ||
|
|
51530e03a5 | ||
|
|
bca4c3d5fa | ||
|
|
66263dd7b3 | ||
|
|
9e6384bf79 | ||
|
|
6b0ce64d5e | ||
|
|
3b080058ed | ||
|
|
00996a2a02 | ||
|
|
c0299f4a1e | ||
|
|
e09105de98 | ||
|
|
dcd544082e | ||
|
|
1013ce68c1 | ||
|
|
aea84b03fc | ||
|
|
7608db4b0e | ||
|
|
62f1c4b086 | ||
|
|
ab6864f3b4 | ||
|
|
b8bd80a5f4 | ||
|
|
fffc5ddd1f | ||
|
|
cd4c858048 | ||
|
|
3fb1bd3d1d | ||
|
|
75aff7f1a6 | ||
|
|
3f3c5c8ac5 | ||
|
|
40b66a83f7 | ||
|
|
0b15d66dc0 | ||
|
|
ceacda6c6a | ||
|
|
0a22ac9209 | ||
|
|
ba1d54d672 | ||
|
|
b5a18dc71a | ||
|
|
4a0141511d | ||
|
|
f0a6e49984 | ||
|
|
f60e1d1230 | ||
|
|
625db78abf | ||
|
|
b470ffdb56 | ||
|
|
78095afdbc | ||
|
|
e83cdc6721 | ||
|
|
7ba000fe45 | ||
|
|
cae6a36c19 | ||
|
|
8549895373 | ||
|
|
efa907881e | ||
|
|
744cae8270 | ||
|
|
28899243b1 | ||
|
|
267288ba19 | ||
|
|
3487d05fac | ||
|
|
031186a8e6 | ||
|
|
f970c9fddc | ||
|
|
e9ceaaa2bb | ||
|
|
0e7c436df5 | ||
|
|
745e23f2c3 | ||
|
|
1f7b8a6583 | ||
|
|
b2790c6df5 | ||
|
|
f5e3c1c348 | ||
|
|
ba955f003e | ||
|
|
75e0ffbbce | ||
|
|
9168dd7d1d | ||
|
|
ee5f871f1a | ||
|
|
c896c8fda4 | ||
|
|
0e895a1e28 | ||
|
|
d95081094f | ||
|
|
011dda9816 | ||
|
|
34c377328f | ||
|
|
382204f702 | ||
|
|
19aed55e52 | ||
|
|
9d1e1fb64a | ||
|
|
d75cda0cc3 | ||
|
|
a4c7f68320 | ||
|
|
547431da0b | ||
|
|
c3fdc098fe | ||
|
|
6ed276190d | ||
|
|
59265265d9 | ||
|
|
8d9370b005 | ||
|
|
fd97c6e7a7 | ||
|
|
297da0745f | ||
|
|
cb231e02a6 | ||
|
|
298b51fefa | ||
|
|
80befa1c94 | ||
|
|
11dce20534 | ||
|
|
56bd079f96 | ||
|
|
733b49ae42 | ||
|
|
08ed4c4201 | ||
|
|
09d5125278 | ||
|
|
6e1a3f3c27 | ||
|
|
5b3743d9a6 | ||
|
|
ec135b1b8e | ||
|
|
60e34cff11 | ||
|
|
da8dc9f5aa | ||
|
|
27aa44acb5 | ||
|
|
ff1d051359 | ||
|
|
85e32534fa | ||
|
|
bc49b7d03a | ||
|
|
ee97068208 | ||
|
|
0f7e069dd9 | ||
|
|
3c3c6d5efe | ||
|
|
f163054557 | ||
|
|
fb80bea056 | ||
|
|
abad5c3028 | ||
|
|
d0c164220d | ||
|
|
34b1a86a68 | ||
|
|
06f5da7f5b | ||
|
|
1e80ccb8d3 | ||
|
|
8ad34a689a | ||
|
|
a421e10e3b | ||
|
|
1c4b42bb95 | ||
|
|
bba3be457b | ||
|
|
3abfbb8ba1 | ||
|
|
331a35070c | ||
|
|
99ad690382 | ||
|
|
4301b21702 | ||
|
|
fceab582fe | ||
|
|
e8a4ed40a5 | ||
|
|
b698c1437b | ||
|
|
14cea92e06 | ||
|
|
3a8e04cac6 | ||
|
|
5b01721440 | ||
|
|
aad2b35ac9 | ||
|
|
f8371daeb8 | ||
|
|
74519977fd | ||
|
|
c0bea158d4 | ||
|
|
70686b4913 | ||
|
|
14502dd715 | ||
|
|
8ee986536b | ||
|
|
8ed82798d2 | ||
|
|
ebfe10b7df | ||
|
|
4aa26180ca | ||
|
|
89496448d9 | ||
|
|
dfa0a3979a | ||
|
|
396cd7db4f | ||
|
|
0351d59060 | ||
|
|
6f0b0e976d | ||
|
|
dd5d687014 | ||
|
|
5d8b0891bd | ||
|
|
7dc95f63d3 | ||
|
|
a7adc5865b | ||
|
|
cdbe5766fa | ||
|
|
b1cac0731c | ||
|
|
fc8de511c6 | ||
|
|
defdb8ff1c | ||
|
|
9a08a8478f | ||
|
|
a6f7a0180b | ||
|
|
5a59df4476 | ||
|
|
1df9d7c575 | ||
|
|
65008b11f7 | ||
|
|
b18314878a | ||
|
|
11a951c679 | ||
|
|
c67e3ff7b9 | ||
|
|
e5a633cc41 | ||
|
|
3724d847cf | ||
|
|
b6063b5c60 | ||
|
|
09362f0eac | ||
|
|
32b3f3f569 | ||
|
|
0d08362291 | ||
|
|
9f120a80a7 | ||
|
|
2eb6fd754e | ||
|
|
9f4a8973d0 | ||
|
|
a4d9355060 | ||
|
|
5a7545afbd | ||
|
|
8affa33718 | ||
|
|
4d25ea1760 | ||
|
|
6ec8e2ccec | ||
|
|
97d0ae6527 | ||
|
|
50a74d0eda | ||
|
|
f9e03b5eaa | ||
|
|
ad571bd898 | ||
|
|
de8ef9aee4 | ||
|
|
21f75da2f6 | ||
|
|
233dbf8075 | ||
|
|
d8f1ba9b3d | ||
|
|
1241f18215 | ||
|
|
b6604882eb | ||
|
|
a9c9d5c499 | ||
|
|
9a827d937e | ||
|
|
38594f889a | ||
|
|
04c17e45b3 | ||
|
|
730a8de024 | ||
|
|
7eac2fe3e4 | ||
|
|
267243d959 | ||
|
|
f587262c8e | ||
|
|
ebf458dbd0 | ||
|
|
f64b5559dd | ||
|
|
2ddcd5f678 | ||
|
|
cac715937a | ||
|
|
39f43feb11 | ||
|
|
58d65b17ea | ||
|
|
4314f0cac3 | ||
|
|
d4da369930 | ||
|
|
6f1876b618 | ||
|
|
c6e872ceb0 | ||
|
|
72d809819f | ||
|
|
dd09ef3362 | ||
|
|
aa7941fae2 | ||
|
|
35af4a8f35 | ||
|
|
a01fd3dd76 | ||
|
|
d220da89d1 | ||
|
|
55c75e9299 | ||
|
|
616ea87a0a | ||
|
|
319ba2fe75 | ||
|
|
d79eeff779 | ||
|
|
26d38748db | ||
|
|
5c124234bb | ||
|
|
b991c9a8a0 | ||
|
|
681af396b8 | ||
|
|
cac0eaa6c3 | ||
|
|
a64fa2c18f | ||
|
|
f07640850b | ||
|
|
ab665c8c56 | ||
|
|
e43586ffac | ||
|
|
9cc243837d | ||
|
|
de7e3baabc | ||
|
|
7ec9804540 | ||
|
|
5e29afcb57 | ||
|
|
0a1085d9be | ||
|
|
0439d53704 | ||
|
|
7c9116af2e | ||
|
|
5ac2ff4521 | ||
|
|
8565a3e472 | ||
|
|
3648bc8cb0 | ||
|
|
70584af9c0 | ||
|
|
73121eda9d | ||
|
|
381554f8bc | ||
|
|
768e92b0e9 | ||
|
|
98333b7dcf | ||
|
|
4dc1cb1ba1 | ||
|
|
4e0007780c | ||
|
|
506019dd62 | ||
|
|
10f0c3e08e | ||
|
|
fa2950a04b | ||
|
|
ebfb62ca49 | ||
|
|
96023e81af | ||
|
|
e30be60bc4 | ||
|
|
7bfafec128 | ||
|
|
9c07d0ff5d | ||
|
|
e12d2bc486 | ||
|
|
72a85b396c | ||
|
|
87786091bb | ||
|
|
784494274b | ||
|
|
68012dd92c | ||
|
|
a37d2a1364 | ||
|
|
e40be775fe | ||
|
|
64e6924132 | ||
|
|
4bbf47086d | ||
|
|
7c674bc255 | ||
|
|
cc662c102c | ||
|
|
6b9a2d791b | ||
|
|
4551e8759b | ||
|
|
9442976bdb | ||
|
|
8d07df176f | ||
|
|
4b22aff33e | ||
|
|
93dee254d0 | ||
|
|
a29b598205 | ||
|
|
e3b20eaae9 | ||
|
|
d369fb0f94 | ||
|
|
d816bca42f | ||
|
|
d6bb11c4e9 | ||
|
|
2fdcefac05 | ||
|
|
044c3cc11e | ||
|
|
bd9223b525 | ||
|
|
347703dab2 | ||
|
|
f9a0e450e1 | ||
|
|
f6b8cdd1f5 | ||
|
|
6727013302 | ||
|
|
cda12a2660 | ||
|
|
c3c2072472 | ||
|
|
bfc226fdc0 | ||
|
|
fd28e1a7fb | ||
|
|
b11911f5e5 | ||
|
|
a1587d070f | ||
|
|
df2f43bc61 | ||
|
|
895e8eea52 | ||
|
|
97d6249f3b | ||
|
|
7a8ed98eb5 | ||
|
|
d611eece19 | ||
|
|
a99320f5a4 | ||
|
|
c97484943a | ||
|
|
547d9bd844 | ||
|
|
1a65aab05a | ||
|
|
2e869aeb86 | ||
|
|
d729776575 | ||
|
|
895c436405 | ||
|
|
4ae2932792 | ||
|
|
a52be2bdbb | ||
|
|
31c4792216 | ||
|
|
39fd9c0b47 | ||
|
|
9c25df3402 | ||
|
|
fb150b5038 | ||
|
|
8cff3a167e | ||
|
|
2be1431f60 | ||
|
|
255b7ed7f6 | ||
|
|
58fd27399e | ||
|
|
65d2898ff0 | ||
|
|
5f88ba1e47 | ||
|
|
ab569461d8 | ||
|
|
7093fc670b | ||
|
|
6f2b030253 | ||
|
|
0e61e679af | ||
|
|
b40998e1b5 | ||
|
|
174d701bc3 | ||
|
|
f2143d08b9 | ||
|
|
1273e2620d | ||
|
|
c719f6e37e | ||
|
|
37922d8ce0 | ||
|
|
7b79a31f40 | ||
|
|
9a09406f77 | ||
|
|
9bdb778478 | ||
|
|
9621dafe46 | ||
|
|
d7c9837844 | ||
|
|
9087fd904d | ||
|
|
27bb7803ae | ||
|
|
66ac6942b6 | ||
|
|
c0e1086f2c | ||
|
|
ffa751c617 | ||
|
|
b8ad60a2d6 | ||
|
|
5db0aac816 | ||
|
|
20980fe54d | ||
|
|
3fae7c5184 | ||
|
|
fb54acfe69 | ||
|
|
47889a8f22 | ||
|
|
8d22c3869b | ||
|
|
0e69edd066 | ||
|
|
235ed4afe0 | ||
|
|
627cb7f774 | ||
|
|
09021af350 | ||
|
|
31c280d1fa | ||
|
|
629f344f34 | ||
|
|
db5f924e24 | ||
|
|
9be3eb282a | ||
|
|
9255a035f4 | ||
|
|
effd891a16 | ||
|
|
fbdc23f482 | ||
|
|
8ab0d5acdd | ||
|
|
13db35cbf5 | ||
|
|
0f2d480e3c | ||
|
|
9edc61e37b | ||
|
|
f4dab6aac5 | ||
|
|
5af323102a | ||
|
|
9e0550d140 | ||
|
|
0997fad8ec | ||
|
|
0d1701c509 | ||
|
|
f2f62f93ea | ||
|
|
8a329f66fb | ||
|
|
05d4c52918 | ||
|
|
8fd0dd0cc0 | ||
|
|
8eea5811ba | ||
|
|
a154c2adab | ||
|
|
10bf4ed576 | ||
|
|
60d12dd395 | ||
|
|
b4e9be3c52 | ||
|
|
dcebae6d4a | ||
|
|
8749696538 | ||
|
|
0d776bcd26 | ||
|
|
2d6ed47cf2 | ||
|
|
9beea23f63 | ||
|
|
ea06434425 | ||
|
|
6508eff95e | ||
|
|
69930684a9 | ||
|
|
b1931a3eda | ||
|
|
63b44d4e32 | ||
|
|
f7cb8d8141 | ||
|
|
48c857e02c | ||
|
|
2978d43a5d | ||
|
|
a264766584 | ||
|
|
442dc58e0f | ||
|
|
25460c652c | ||
|
|
31a98f0a1e | ||
|
|
36c44b6f45 | ||
|
|
27426b18d1 | ||
|
|
3ea9ce1c8c | ||
|
|
f03a9bfcf3 | ||
|
|
4dfc636c84 | ||
|
|
5fe4312c6c | ||
|
|
63e675a6bb | ||
|
|
e92aeac7d7 | ||
|
|
f1f7eac1f2 | ||
|
|
eff0c84553 | ||
|
|
58c8ce61c7 | ||
|
|
6ac5e6953a | ||
|
|
5d9ad59af2 | ||
|
|
3c48a05437 | ||
|
|
4462124ff2 | ||
|
|
373f557ef7 | ||
|
|
495e561398 | ||
|
|
d24a579033 | ||
|
|
77130424b4 | ||
|
|
eb30688937 | ||
|
|
880bac0633 | ||
|
|
60fdcddcb5 | ||
|
|
851d6a987f | ||
|
|
9bebd7b35f | ||
|
|
309acb9597 | ||
|
|
a56887167e | ||
|
|
e984dff4e4 | ||
|
|
685e4d446b | ||
|
|
8af680f307 | ||
|
|
6c60cce60d | ||
|
|
5882a675bb | ||
|
|
a5e95845b3 | ||
|
|
5b83d81e40 | ||
|
|
c8e5ad564d | ||
|
|
5edfa273ff | ||
|
|
4db57bcb10 | ||
|
|
3f13340903 | ||
|
|
6abb53c9d3 | ||
|
|
fdd20a519e | ||
|
|
67cc49f333 | ||
|
|
31a34cd0b5 | ||
|
|
ef8c08ba99 | ||
|
|
2991ca6c6f | ||
|
|
52bace18b2 | ||
|
|
767d14ae4f | ||
|
|
1a5c911e36 | ||
|
|
6e42a04e43 | ||
|
|
28be2cfeef | ||
|
|
8be168fd87 | ||
|
|
eee95fef57 | ||
|
|
9ea179b052 | ||
|
|
6868280409 | ||
|
|
e00b764454 | ||
|
|
999613c686 | ||
|
|
c2661d7eb5 | ||
|
|
4d21dd1f47 | ||
|
|
a0a0e57527 | ||
|
|
d8af0d0b4e | ||
|
|
113288e3b0 | ||
|
|
afecfd7c2d | ||
|
|
94d89aac5f | ||
|
|
8831b13efc | ||
|
|
01f99da03a | ||
|
|
080654e3ef | ||
|
|
2ac2eb2a61 | ||
|
|
61b940b705 | ||
|
|
4a4f87e017 | ||
|
|
6d5e7f63a7 | ||
|
|
f77285f375 | ||
|
|
dc5d03a6dc | ||
|
|
ea0961b7f6 | ||
|
|
33d9f9774c | ||
|
|
86097fa038 | ||
|
|
70d9dbc45a | ||
|
|
3926fd3a20 | ||
|
|
7861cf1146 | ||
|
|
0516b86a6e | ||
|
|
ec735d3e9b | ||
|
|
1c5c070983 | ||
|
|
a5c02b73dc | ||
|
|
918b920670 | ||
|
|
de67d2e27e | ||
|
|
bc89df04cb | ||
|
|
c26a4cf082 | ||
|
|
6e1a866b13 | ||
|
|
f91986ad0d | ||
|
|
795cc23f3e | ||
|
|
a3695bd4a0 | ||
|
|
08dc521daf | ||
|
|
8b916d21b1 | ||
|
|
c40f47a78a | ||
|
|
e9fb470b06 | ||
|
|
343d049772 | ||
|
|
86f9480da4 | ||
|
|
8696b610ca | ||
|
|
6f13227eda | ||
|
|
525d190f91 | ||
|
|
58d5110e61 | ||
|
|
1e0154335b | ||
|
|
76e53c7bc5 | ||
|
|
413c29a5e4 | ||
|
|
30bb6143c1 | ||
|
|
cfb08be1a8 | ||
|
|
b5bbb7fb1c | ||
|
|
a76c33f8cc | ||
|
|
991ac727c6 | ||
|
|
810306b8f3 | ||
|
|
6c22bdb3bd | ||
|
|
569a78649f | ||
|
|
6a0d3e98bc | ||
|
|
7caec1ec33 | ||
|
|
7fd3fb48b1 | ||
|
|
3809321037 | ||
|
|
eef695bdf0 | ||
|
|
ab01ab1e4d | ||
|
|
a32a3b37db | ||
|
|
c8d8a108a7 | ||
|
|
7afd9efcc5 | ||
|
|
56ded87ad2 | ||
|
|
82e503339b | ||
|
|
713d0c7ace | ||
|
|
25ad6e3f8f | ||
|
|
df0197b617 | ||
|
|
a89c4f01ad | ||
|
|
ae67099633 | ||
|
|
57542d3a5c | ||
|
|
9a1da14116 | ||
|
|
ed050d753d | ||
|
|
8bec363710 | ||
|
|
7c68e190a9 | ||
|
|
7ebf5ea3d1 | ||
|
|
11e0435a4b | ||
|
|
d15ee57cd1 | ||
|
|
56d660b7fd | ||
|
|
792958e693 | ||
|
|
914e67dc04 | ||
|
|
b50a7ccb61 | ||
|
|
f827709d42 | ||
|
|
36abb42175 | ||
|
|
40f3b1b4c8 | ||
|
|
4f35e25688 | ||
|
|
270e88edd7 | ||
|
|
5ded171247 | ||
|
|
88f6076f3c | ||
|
|
b4d12e08dd | ||
|
|
332dd988e4 | ||
|
|
bce8db41d7 | ||
|
|
f6fd70245d | ||
|
|
4ff0a055d6 | ||
|
|
c9140267a5 | ||
|
|
72fcee4e5e | ||
|
|
9c8e512edd | ||
|
|
3c191af34a | ||
|
|
5e0b2d7370 | ||
|
|
5994abd453 | ||
|
|
67a2d119c0 | ||
|
|
114215088a | ||
|
|
a78e2b793e | ||
|
|
519ed3834e | ||
|
|
22647135fa | ||
|
|
58c741e9ca | ||
|
|
ef9083089e | ||
|
|
5de1582a0a | ||
|
|
39c864e31f | ||
|
|
320cb63df4 | ||
|
|
c246222ded | ||
|
|
b7edb2873c | ||
|
|
89f2032c0d | ||
|
|
d2f8230093 | ||
|
|
9f6b5d169a | ||
|
|
e56708d4aa | ||
|
|
304156c20e | ||
|
|
31e1566e1d | ||
|
|
3908637056 | ||
|
|
abee301f3d | ||
|
|
9b1d3f8f3c | ||
|
|
3513eaf701 | ||
|
|
08a840afe4 | ||
|
|
370f5d461c | ||
|
|
8efc8458e1 | ||
|
|
6485717c52 | ||
|
|
1d5bbd11a8 | ||
|
|
bc403742b5 | ||
|
|
c7f963f57e | ||
|
|
afb6684bde | ||
|
|
ee3d772235 | ||
|
|
1af08f7085 | ||
|
|
ccf23fa273 | ||
|
|
f701defc5f | ||
|
|
c606f05bf8 | ||
|
|
a646153615 | ||
|
|
60380afe15 | ||
|
|
d4b0a977c9 | ||
|
|
f86156ad10 | ||
|
|
1836ee854f | ||
|
|
c37cdeec9f | ||
|
|
b0b2b17908 | ||
|
|
2918732481 | ||
|
|
5a4d5ddb9d | ||
|
|
55afcf678d | ||
|
|
16c7cf9b5e | ||
|
|
432bd29c1c | ||
|
|
a87914ef23 | ||
|
|
041530a953 | ||
|
|
9d4c55161a | ||
|
|
a706d1df00 | ||
|
|
b15b2e666f | ||
|
|
5d4678364e | ||
|
|
1c0f470032 | ||
|
|
9590526430 | ||
|
|
1c6dfda83c | ||
|
|
a8be12940e | ||
|
|
4b5046366b | ||
|
|
a0fff90c26 | ||
|
|
a8daedac5e | ||
|
|
5fa26fb3ac | ||
|
|
ea3e297175 | ||
|
|
a11bd6ebd9 | ||
|
|
9889bf50a2 | ||
|
|
d75fb2deda | ||
|
|
6355a5b28d | ||
|
|
595bbee41e | ||
|
|
cb3f3a1f64 | ||
|
|
0e44838905 | ||
|
|
64cd268fc7 | ||
|
|
f048dd81f2 | ||
|
|
5746f2214c | ||
|
|
099af669d4 | ||
|
|
79cac706a7 | ||
|
|
df229074ac | ||
|
|
191c27e856 | ||
|
|
e5ee01b43c | ||
|
|
c46b040f6f | ||
|
|
72e4794f5b | ||
|
|
c30b65a0ea | ||
|
|
1cb08ff60c | ||
|
|
d3d7fd9317 | ||
|
|
acf0f97663 | ||
|
|
34bd87cea7 | ||
|
|
228f11262e | ||
|
|
9683e0f1cc | ||
|
|
674ae6d571 | ||
|
|
690d44e2e6 |
40
.gitignore
vendored
Normal file
40
.gitignore
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
#mac
|
||||
.DS_Store
|
||||
|
||||
#projects
|
||||
.project
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
bin/*
|
||||
test/bin/*
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
#doc
|
||||
|
||||
doc/html
|
||||
141
README.md
Normal file
141
README.md
Normal file
@@ -0,0 +1,141 @@
|
||||
thread
|
||||
======
|
||||
|
||||
Portable C++ multi-threading. C++11, C++14.
|
||||
|
||||
### License
|
||||
|
||||
Distributed under the [Boost Software License, Version 1.0](http://boost.org/LICENSE_1_0.txt).
|
||||
|
||||
### Current Jenkins CI Test Status for unstable (develop) branch
|
||||
Overall build (nightly): <a href='https://ci.nedprod.com/view/All/job/Boost.Thread%20Build/'><img src='https://ci.nedprod.com/buildStatus/icon?job=Boost.Thread%20Build'></a> Overall tests (weekly, on Sundays): <a href='https://ci.nedprod.com/view/All/job/Boost.Thread%20Test/'><img src='https://ci.nedprod.com/buildStatus/icon?job=Boost.Thread%20Test'></a>
|
||||
|
||||
#### Build (nightly):
|
||||
<table id="configuration-matrix" width="100%" border="1">
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="6" valign="top">android-ndk</td><td class="matrix-leftcolumn" rowspan="2" valign="top">c++03</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=g++-4.6,LINKTYPE=static,label=android-ndk/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.6</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=g++-4.8,LINKTYPE=static,label=android-ndk/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.8</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=clang++-3.5,LINKTYPE=static,label=android-ndk/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.5</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=g++-4.6,LINKTYPE=shared,label=android-ndk/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.6</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=g++-4.8,LINKTYPE=shared,label=android-ndk/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.8</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=clang++-3.5,LINKTYPE=shared,label=android-ndk/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.5</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="2" valign="top">c++11</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=g++-4.8,LINKTYPE=static,label=android-ndk/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.8</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=clang++-3.5,LINKTYPE=static,label=android-ndk/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.5</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=g++-4.8,LINKTYPE=shared,label=android-ndk/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.8</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=clang++-3.5,LINKTYPE=shared,label=android-ndk/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.5</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="2" valign="top">c++14</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=clang++-3.5,LINKTYPE=static,label=android-ndk/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.5</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=clang++-3.5,LINKTYPE=shared,label=android-ndk/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.5</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="6" valign="top">winphone8</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td/>
|
||||
</tr>
|
||||
<tr>
|
||||
<td/>
|
||||
</tr>
|
||||
<tr>
|
||||
<td/>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="2" valign="top">c++14</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=msvc-11.0,LINKTYPE=static,label=winphone8/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>msvc-11.0</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=msvc-12.0,LINKTYPE=static,label=winphone8/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>msvc-12.0</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=msvc-14.0,LINKTYPE=static,label=winphone8/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>msvc-14.0</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=msvc-11.0,LINKTYPE=shared,label=winphone8/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>msvc-11.0</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=msvc-12.0,LINKTYPE=shared,label=winphone8/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>msvc-12.0</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=msvc-14.0,LINKTYPE=shared,label=winphone8/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>msvc-14.0</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="6" valign="top">arm-gcc-clang</td><td class="matrix-leftcolumn" rowspan="2" valign="top">c++03</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=g++-4.9,LINKTYPE=static,label=arm-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.9</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=clang++-3.5,LINKTYPE=static,label=arm-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.5</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=g++-4.9,LINKTYPE=shared,label=arm-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.9</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=clang++-3.5,LINKTYPE=shared,label=arm-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.5</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="2" valign="top">c++11</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=g++-4.9,LINKTYPE=static,label=arm-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.9</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=clang++-3.5,LINKTYPE=static,label=arm-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.5</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=g++-4.9,LINKTYPE=shared,label=arm-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.9</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=clang++-3.5,LINKTYPE=shared,label=arm-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.5</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="2" valign="top">c++14</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=g++-4.9,LINKTYPE=static,label=arm-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.9</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=g++-4.9,LINKTYPE=shared,label=arm-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.9</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="6" valign="top">freebsd10-clang3.3</td><td class="matrix-leftcolumn" rowspan="2" valign="top">c++03</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=clang++-3.3,LINKTYPE=static,label=freebsd10-clang3.3/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.3</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=clang++-3.3,LINKTYPE=shared,label=freebsd10-clang3.3/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.3</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="2" valign="top">c++11</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=clang++-3.3,LINKTYPE=static,label=freebsd10-clang3.3/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.3</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=clang++-3.3,LINKTYPE=shared,label=freebsd10-clang3.3/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.3</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td/>
|
||||
</tr>
|
||||
<tr>
|
||||
<td/>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="6" valign="top">linux-gcc-clang</td><td class="matrix-leftcolumn" rowspan="2" valign="top">c++03</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=g++-4.6,LINKTYPE=static,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.6</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=g++-4.7,LINKTYPE=static,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.7</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=clang++-3.2,LINKTYPE=static,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.2</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=clang++-3.3,LINKTYPE=static,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.3</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=clang++-3.4,LINKTYPE=static,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.4</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=g++-4.6,LINKTYPE=shared,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.6</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=g++-4.7,LINKTYPE=shared,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.7</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=clang++-3.2,LINKTYPE=shared,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.2</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=clang++-3.3,LINKTYPE=shared,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.3</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=clang++-3.4,LINKTYPE=shared,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.4</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="2" valign="top">c++11</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=g++-4.7,LINKTYPE=static,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.7</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=clang++-3.2,LINKTYPE=static,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.2</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=clang++-3.3,LINKTYPE=static,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.3</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=clang++-3.4,LINKTYPE=static,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.4</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=g++-4.7,LINKTYPE=shared,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.7</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=clang++-3.2,LINKTYPE=shared,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.2</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=clang++-3.3,LINKTYPE=shared,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.3</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=clang++-3.4,LINKTYPE=shared,label=linux-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.4</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td/>
|
||||
</tr>
|
||||
<tr>
|
||||
<td/>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="6" valign="top">linux64-gcc-clang</td><td class="matrix-leftcolumn" rowspan="2" valign="top">c++03</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=clang++-analyse,LINKTYPE=static,label=linux64-gcc-clang/"><img height="24" alt="Unstable" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/yellow.png" tooltip="Unstable"/></a>clang++-analyse</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=g++-4.8,LINKTYPE=static,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.8</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=g++-4.9,LINKTYPE=static,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.9</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=clang++-3.5,LINKTYPE=static,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.5</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=clang++-analyse,LINKTYPE=shared,label=linux64-gcc-clang/"><img height="24" alt="Unstable" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/yellow.png" tooltip="Unstable"/></a>clang++-analyse</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=g++-4.8,LINKTYPE=shared,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.8</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=g++-4.9,LINKTYPE=shared,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.9</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=clang++-3.5,LINKTYPE=shared,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.5</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="2" valign="top">c++11</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=clang++-analyse,LINKTYPE=static,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-analyse</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=g++-4.8,LINKTYPE=static,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.8</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=g++-4.9,LINKTYPE=static,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.9</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=clang++-3.5,LINKTYPE=static,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.5</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=clang++-analyse,LINKTYPE=shared,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-analyse</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=g++-4.8,LINKTYPE=shared,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.8</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=g++-4.9,LINKTYPE=shared,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.9</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=clang++-3.5,LINKTYPE=shared,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.5</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="2" valign="top">c++14</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=clang++-analyse,LINKTYPE=static,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-analyse</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=g++-4.9,LINKTYPE=static,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.9</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=clang++-3.5,LINKTYPE=static,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.5</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=clang++-analyse,LINKTYPE=shared,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-analyse</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=g++-4.9,LINKTYPE=shared,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>g++-4.9</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=clang++-3.5,LINKTYPE=shared,label=linux64-gcc-clang/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>clang++-3.5</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="6" valign="top">win8-msvc-mingw</td><td class="matrix-leftcolumn" rowspan="2" valign="top">c++03</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=mingw32,LINKTYPE=static,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>mingw32</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=mingw64,LINKTYPE=static,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>mingw64</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=mingw32,LINKTYPE=shared,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>mingw32</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++03,CXX=mingw64,LINKTYPE=shared,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>mingw64</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="2" valign="top">c++11</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=mingw32,LINKTYPE=static,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>mingw32</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=mingw64,LINKTYPE=static,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>mingw64</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=mingw32,LINKTYPE=shared,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>mingw32</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++11,CXX=mingw64,LINKTYPE=shared,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>mingw64</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="2" valign="top">c++14</td><td class="matrix-leftcolumn" rowspan="1" valign="top">static</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=msvc-10.0,LINKTYPE=static,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>msvc-10.0</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=msvc-11.0,LINKTYPE=static,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>msvc-11.0</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=msvc-12.0,LINKTYPE=static,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>msvc-12.0</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=msvc-14.0,LINKTYPE=static,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>msvc-14.0</div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="matrix-leftcolumn" rowspan="1" valign="top">shared</td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=msvc-analyse,LINKTYPE=shared,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>msvc-analyse</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=msvc-10.0,LINKTYPE=shared,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>msvc-10.0</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=msvc-11.0,LINKTYPE=shared,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>msvc-11.0</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=msvc-12.0,LINKTYPE=shared,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>msvc-12.0</div></td><td class="matrix-cell"><div><a class="model-link inside" href="https://ci.nedprod.com/job/Boost.Thread%20Build/CPPSTD=c++14,CXX=msvc-14.0,LINKTYPE=shared,label=win8-msvc-mingw/"><img height="24" alt="Success" width="24" src="https://ci.nedprod.com/static/5e289396/images/24x24/blue.png" tooltip="Success"/></a>msvc-14.0</div></td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -1,2 +0,0 @@
|
||||
bin*
|
||||
*.pdb
|
||||
336
build/Jamfile.v2
336
build/Jamfile.v2
@@ -1,39 +1,315 @@
|
||||
# (C) Copyright Vladimir Prus, David Abrahams, Michael Stevens, Hartmut Kaiser,
|
||||
# William E Kempf 2002-2006
|
||||
# Use, modification and distribution are subject to the
|
||||
# Boost Software License, Version 1.0. (See accompanying file
|
||||
# LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
# $Id$
|
||||
# Copyright 2006-2007 Roland Schwarz.
|
||||
# Copyright 2007 Anthony Williams
|
||||
# Copyright 2011-2012 Vicente J.Botet Escriba.
|
||||
# Distributed under the Boost Software License, Version 1.0. (See
|
||||
# accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#########################################################################
|
||||
# The boost threading library can be built on top of different API's
|
||||
# Currently this is the win32 API and the pthreads API.
|
||||
# Pthread is native on unix variants.
|
||||
# To get pthread on windows you need the pthread win32 library
|
||||
# http://sourceware.org/pthreads-win32 which is available under LGPL.
|
||||
#
|
||||
# You need to provide the include path and lib path in the variables
|
||||
# PTW32_INCLUDE and PTW32_LIB respectively. You can specify these
|
||||
# paths in site-config.jam, user-config.jam or in the environment.
|
||||
# A new feature is provided to request a specific API:
|
||||
# <threadapi>win32 and <threadapi)pthread.
|
||||
#
|
||||
# The naming of the resulting libraries is mostly the same for the
|
||||
# variant native to the build platform, i.e.
|
||||
# boost_thread and the boost specific tagging.
|
||||
# For the library variant that is not native on the build platform
|
||||
# an additional tag is applied:
|
||||
# boost_thread_pthread for the pthread variant on windows, and
|
||||
# boost_thread_win32 for the win32 variant (likely when built on cygwin).
|
||||
#
|
||||
# To request the pthread variant on windows, from boost root you would
|
||||
# say e.g:
|
||||
# bjam msvc-8.0 --with-thread install threadapi=pthread
|
||||
#########################################################################
|
||||
|
||||
import os ;
|
||||
|
||||
import feature ;
|
||||
import indirect ;
|
||||
import path ;
|
||||
import configure ;
|
||||
|
||||
project boost/thread
|
||||
: source-location ../src
|
||||
: requirements <link>shared:<define>BOOST_THREAD_BUILD_DLL=1 <threading>multi
|
||||
: default-build <threading>multi
|
||||
: source-location ../src
|
||||
: requirements <threading>multi
|
||||
#<link>static:<define>BOOST_THREAD_STATIC_LINK=1
|
||||
#<link>shared:<define>BOOST_THREAD_DYN_LINK=1
|
||||
<link>static:<define>BOOST_THREAD_BUILD_LIB=1
|
||||
<link>shared:<define>BOOST_THREAD_BUILD_DLL=1
|
||||
-<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
|
||||
<tag>@$(__name__).tag
|
||||
<toolset>gcc:<cxxflags>-Wno-long-long
|
||||
#<define>BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
|
||||
#<define>BOOST_SYSTEM_NO_DEPRECATED
|
||||
#<define>BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS
|
||||
|
||||
<library>/boost/system//boost_system
|
||||
#-pedantic -ansi -std=gnu++0x -Wextra -fpermissive
|
||||
<warnings>all
|
||||
<toolset>gcc:<cxxflags>-Wextra
|
||||
<toolset>gcc:<cxxflags>-pedantic
|
||||
<toolset>gcc:<cxxflags>-Wno-long-long
|
||||
#<toolset>gcc:<cxxflags>-ansi
|
||||
#<toolset>gcc:<cxxflags>-fpermissive
|
||||
<toolset>gcc:<cxxflags>-Wno-variadic-macros
|
||||
#<toolset>gcc:<cxxflags>-Wunused-local-typedefs
|
||||
<toolset>gcc:<cxxflags>-Wunused-function
|
||||
<toolset>gcc:<cxxflags>-Wno-unused-parameter
|
||||
|
||||
<toolset>darwin:<cxxflags>-Wextra
|
||||
<toolset>darwin:<cxxflags>-pedantic
|
||||
#<toolset>darwin:<cxxflags>-ansi
|
||||
<toolset>darwin:<cxxflags>-fpermissive
|
||||
<toolset>darwin:<cxxflags>-Wno-long-long
|
||||
<toolset>darwin:<cxxflags>-Wno-variadic-macros
|
||||
#<toolset>darwin:<cxxflags>-Wunused-local-typedefs
|
||||
<toolset>darwin:<cxxflags>-Wunused-function
|
||||
<toolset>darwin:<cxxflags>-Wno-unused-parameter
|
||||
|
||||
#<toolset>pathscale:<cxxflags>-Wextra
|
||||
<toolset>pathscale:<cxxflags>-Wno-long-long
|
||||
<toolset>pathscale:<cxxflags>-pedantic
|
||||
|
||||
<toolset>clang:<warnings>on
|
||||
<toolset>clang:<cxxflags>-Wextra
|
||||
#<toolset>clang:<cxxflags>-ansi
|
||||
#<toolset>clang:<cxxflags>-fpermissive
|
||||
<toolset>clang:<cxxflags>-Wno-long-long
|
||||
<toolset>clang:<cxxflags>-Wunused-function
|
||||
<toolset>clang:<cxxflags>-Wno-variadic-macros
|
||||
<toolset>clang:<cxxflags>-Wno-unused-parameter
|
||||
|
||||
#<toolset>gcc-mingw-4.4.0:<cxxflags>-fdiagnostics-show-option
|
||||
#<toolset>gcc-mingw-4.5.0:<cxxflags>-fdiagnostics-show-option
|
||||
#<toolset>gcc-mingw-4.6.0:<cxxflags>-fdiagnostics-show-option
|
||||
#<toolset>gcc-mingw-4.6.3:<cxxflags>-fdiagnostics-show-option
|
||||
#<toolset>gcc-mingw-4.7.0:<cxxflags>-fdiagnostics-show-option
|
||||
#<toolset>gcc-mingw-4.8.0:<cxxflags>-fdiagnostics-show-option
|
||||
#<toolset>gcc:<cxxflags>-Wno-missing-field-initializers
|
||||
|
||||
<toolset>darwin-4.6.2:<cxxflags>-Wno-delete-non-virtual-dtor
|
||||
<toolset>darwin-4.7.0:<cxxflags>-Wno-delete-non-virtual-dtor
|
||||
|
||||
#<toolset>clang-2.8:<cxxflags>-Wno-delete-non-virtual-dtor
|
||||
#<toolset>clang-2.8:<cxxflags>-Wno-unused-function
|
||||
#<toolset>clang-2.9:<cxxflags>-Wno-delete-non-virtual-dtor
|
||||
#<toolset>clang-2.9:<cxxflags>-Wno-unused-function
|
||||
<toolset>clang-3.0:<cxxflags>-Wno-delete-non-virtual-dtor
|
||||
#<toolset>clang-3.0:<cxxflags>-Wno-unused-function
|
||||
#<toolset>clang-3.0:<cxxflags>-Wno-unused-variable
|
||||
|
||||
# Note: Some of the remarks from the Intel compiler are disabled
|
||||
# remark #193: zero used for undefined preprocessing identifier "XXX"
|
||||
# remark #304: access control not specified ("public" by default)
|
||||
# remark #593: variable "XXX" was set but never used
|
||||
# remark #1418: external function definition with no prior declaration
|
||||
# remark #2415: variable "XXX" of static storage duration was declared but never referenced
|
||||
|
||||
<toolset>intel:<cxxflags>-wd193,304,383,444
|
||||
<toolset>intel:<cxxflags>-wd593,981
|
||||
<toolset>intel:<cxxflags>-wd1418
|
||||
<toolset>intel:<cxxflags>-wd2415
|
||||
|
||||
<toolset>msvc:<cxxflags>/wd4100
|
||||
<toolset>msvc:<cxxflags>/wd4512
|
||||
<toolset>msvc:<cxxflags>/wd6246
|
||||
|
||||
|
||||
# : default-build <threading>multi
|
||||
: usage-requirements # pass these requirement to dependents (i.e. users)
|
||||
#<link>static:<define>BOOST_THREAD_STATIC_LINK=1
|
||||
#<link>shared:<define>BOOST_THREAD_DYN_LINK=1
|
||||
<link>static:<define>BOOST_THREAD_BUILD_LIB=1
|
||||
<link>shared:<define>BOOST_THREAD_BUILD_DLL=1
|
||||
#<define>BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
|
||||
#<define>BOOST_SYSTEM_NO_DEPRECATED
|
||||
#<define>BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS
|
||||
<library>/boost/system//boost_system
|
||||
;
|
||||
|
||||
CPP_SOURCES =
|
||||
barrier
|
||||
condition
|
||||
exceptions
|
||||
mutex
|
||||
once
|
||||
recursive_mutex
|
||||
# read_write_mutex
|
||||
thread
|
||||
tss_hooks
|
||||
tss_dll
|
||||
tss_pe
|
||||
tss
|
||||
xtime
|
||||
local rule default_threadapi ( )
|
||||
{
|
||||
local api = pthread ;
|
||||
if [ os.name ] = "NT" { api = win32 ; }
|
||||
return $(api) ;
|
||||
}
|
||||
|
||||
feature.feature threadapi : pthread win32 : propagated ;
|
||||
feature.set-default threadapi : [ default_threadapi ] ;
|
||||
|
||||
exe has_atomic_flag_lockfree : ../build/has_atomic_flag_lockfree_test.cpp ;
|
||||
|
||||
rule tag ( name : type ? : property-set )
|
||||
{
|
||||
local result = $(name) ;
|
||||
|
||||
if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB
|
||||
{
|
||||
local api = [ $(property-set).get <threadapi> ] ;
|
||||
|
||||
# non native api gets additional tag
|
||||
if $(api) != [ default_threadapi ] {
|
||||
result = $(result)_$(api) ;
|
||||
}
|
||||
}
|
||||
|
||||
# forward to the boost tagging rule
|
||||
return [ indirect.call $(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
|
||||
$(result) : $(type) : $(property-set) ] ;
|
||||
}
|
||||
|
||||
rule win32_pthread_paths ( properties * )
|
||||
{
|
||||
local result ;
|
||||
local PTW32_INCLUDE ;
|
||||
local PTW32_LIB ;
|
||||
PTW32_INCLUDE = [ modules.peek : PTW32_INCLUDE ] ;
|
||||
PTW32_LIB = [ modules.peek : PTW32_LIB ] ;
|
||||
PTW32_INCLUDE ?= [ modules.peek user-config : PTW32_INCLUDE ] ;
|
||||
PTW32_LIB ?= [ modules.peek user-config : PTW32_LIB ] ;
|
||||
PTW32_INCLUDE ?= [ modules.peek site-config : PTW32_INCLUDE ] ;
|
||||
PTW32_LIB ?= [ modules.peek site-config : PTW32_LIB ] ;
|
||||
|
||||
if ! ( $(PTW32_INCLUDE) && $(PTW32_LIB) )
|
||||
{
|
||||
if ! $(.notified)
|
||||
{
|
||||
echo "************************************************************" ;
|
||||
echo "Trying to build Boost.Thread with pthread support." ;
|
||||
echo "If you need pthread you should specify the paths." ;
|
||||
echo "You can specify them in site-config.jam, user-config.jam" ;
|
||||
echo "or in the environment." ;
|
||||
echo "For example:" ;
|
||||
echo "PTW32_INCLUDE=C:\\Program Files\\ptw32\\Pre-built2\\include" ;
|
||||
echo "PTW32_LIB=C:\\Program Files\\ptw32\\Pre-built2\\lib" ;
|
||||
echo "************************************************************" ;
|
||||
.notified = true ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
local include_path = [ path.make $(PTW32_INCLUDE) ] ;
|
||||
local lib_path = [ path.make $(PTW32_LIB) ] ;
|
||||
local libname = pthread ;
|
||||
if <toolset>msvc in $(properties)
|
||||
{
|
||||
libname = $(libname)VC2.lib ;
|
||||
}
|
||||
if <toolset>gcc in $(properties)
|
||||
{
|
||||
libname = lib$(libname)GC2.a ;
|
||||
}
|
||||
lib_path = [ path.glob $(lib_path) : $(libname) ] ;
|
||||
if ! $(lib_path)
|
||||
{
|
||||
if ! $(.notified)
|
||||
{
|
||||
echo "************************************************************" ;
|
||||
echo "Trying to build Boost.Thread with pthread support." ;
|
||||
echo "But the library" $(libname) "could not be found in path" ;
|
||||
echo $(PTW32_LIB) ;
|
||||
echo "************************************************************" ;
|
||||
.notified = true ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result += <include>$(include_path) ;
|
||||
result += <library>$(lib_path) ;
|
||||
}
|
||||
}
|
||||
return $(result) ;
|
||||
}
|
||||
|
||||
rule usage-requirements ( properties * )
|
||||
{
|
||||
local result ;
|
||||
if <threadapi>pthread in $(properties)
|
||||
{
|
||||
result += <define>BOOST_THREAD_POSIX ;
|
||||
if <target-os>windows in $(properties)
|
||||
{
|
||||
result += [ win32_pthread_paths $(properties) ] ;
|
||||
# TODO: What is for static linking? Is the <library> also needed
|
||||
# in that case?
|
||||
}
|
||||
}
|
||||
|
||||
#if ! <toolset>vacpp in $(properties) || <toolset-vacpp:version>11.1 in $(properties) || <toolset-vacpp:version>12.1.0.1 in $(properties) || <toolset-vacpp:version>12.1 in $(properties)
|
||||
#{
|
||||
result += <library>/boost/chrono//boost_chrono ;
|
||||
#}
|
||||
|
||||
return $(result) ;
|
||||
}
|
||||
|
||||
rule requirements ( properties * )
|
||||
{
|
||||
local result ;
|
||||
|
||||
if <threadapi>pthread in $(properties)
|
||||
{
|
||||
result += <define>BOOST_THREAD_POSIX ;
|
||||
if <target-os>windows in $(properties)
|
||||
{
|
||||
local paths = [ win32_pthread_paths $(properties) ] ;
|
||||
if $(paths)
|
||||
{
|
||||
result += $(paths) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = <build>no ;
|
||||
}
|
||||
}
|
||||
result += <define>BOOST_THREAD_DONT_USE_CHRONO ;
|
||||
if ! [ configure.builds has_atomic_flag_lockfree
|
||||
: $(properties) : "lockfree boost::atomic_flag" ] {
|
||||
result += <library>/boost/atomic//boost_atomic ;
|
||||
}
|
||||
} else {
|
||||
result += <define>BOOST_THREAD_USES_CHRONO ;
|
||||
result += <library>/boost/chrono//boost_chrono ;
|
||||
}
|
||||
|
||||
return $(result) ;
|
||||
}
|
||||
|
||||
alias thread_sources
|
||||
: ## win32 sources ##
|
||||
win32/thread.cpp
|
||||
win32/tss_dll.cpp
|
||||
win32/tss_pe.cpp
|
||||
future.cpp
|
||||
: ## requirements ##
|
||||
<threadapi>win32
|
||||
;
|
||||
|
||||
alias thread_sources
|
||||
: ## pthread sources ##
|
||||
pthread/thread.cpp
|
||||
pthread/once.cpp
|
||||
future.cpp
|
||||
: ## requirements ##
|
||||
<threadapi>pthread
|
||||
;
|
||||
|
||||
explicit thread_sources ;
|
||||
|
||||
lib boost_thread
|
||||
: $(CPP_SOURCES).cpp
|
||||
: <link>shared:<define>BOOST_THREAD_BUILD_DLL=1
|
||||
<link>static:<define>BOOST_THREAD_BUILD_LIB=1
|
||||
: # default build
|
||||
: <link>shared:<define>BOOST_THREAD_BUILD_DLL=1
|
||||
<link>static:<define>BOOST_THREAD_BUILD_LIB=1
|
||||
;
|
||||
: thread_sources
|
||||
: <conditional>@requirements
|
||||
:
|
||||
: <link>shared:<define>BOOST_THREAD_USE_DLL=1
|
||||
<link>static:<define>BOOST_THREAD_USE_LIB=1
|
||||
<conditional>@usage-requirements
|
||||
;
|
||||
|
||||
13
build/has_atomic_flag_lockfree_test.cpp
Normal file
13
build/has_atomic_flag_lockfree_test.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) 2013, Petr Machata, Red Hat Inc.
|
||||
//
|
||||
// Use modification and distribution are subject to the boost Software
|
||||
// License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt).
|
||||
|
||||
#include "../../../boost/atomic.hpp"
|
||||
#include "../../../boost/static_assert.hpp"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
BOOST_STATIC_ASSERT(BOOST_ATOMIC_FLAG_LOCK_FREE);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,11 +1,32 @@
|
||||
# Copyright (C) 2001-2003
|
||||
# William E. Kempf
|
||||
# (C) Copyright 2008-11 Anthony Williams
|
||||
# (C) Copyright 2011-12 Vicente J. Botet Escriba
|
||||
#
|
||||
# Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
import toolset ;
|
||||
toolset.using doxygen ;
|
||||
path-constant boost-images : ../../../doc/src/images ;
|
||||
|
||||
xml thread : thread.qbk ;
|
||||
|
||||
boostbook standalone
|
||||
:
|
||||
thread
|
||||
:
|
||||
# HTML options first:
|
||||
# Use graphics not text for navigation:
|
||||
<xsl:param>navig.graphics=1
|
||||
# How far down we chunk nested sections, basically all of them:
|
||||
<xsl:param>chunk.section.depth=2
|
||||
# Don't put the first section on the same page as the TOC:
|
||||
<xsl:param>chunk.first.sections=1
|
||||
# How far down sections get TOC's
|
||||
<xsl:param>toc.section.depth=4
|
||||
# Max depth in each TOC:
|
||||
<xsl:param>toc.max.depth=2
|
||||
# How far down we go with TOC's
|
||||
<xsl:param>generate.section.toc.level=10
|
||||
# Path for links to Boost:
|
||||
<xsl:param>boost.root=../../../..
|
||||
;
|
||||
|
||||
boostbook thread : thread.xml ;
|
||||
|
||||
|
||||
23
doc/acknowledgements.qbk
Normal file
23
doc/acknowledgements.qbk
Normal file
@@ -0,0 +1,23 @@
|
||||
[/
|
||||
(C) Copyright 2007-8 Anthony Williams.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:acknowledgements Acknowledgments]
|
||||
|
||||
The original implementation of __boost_thread__ was written by William Kempf, with contributions from numerous others. This new
|
||||
version initially grew out of an attempt to rewrite __boost_thread__ to William Kempf's design with fresh code that could be
|
||||
released under the Boost Software License. However, as the C++ Standards committee have been actively discussing standardizing a
|
||||
thread library for C++, this library has evolved to reflect the proposals, whilst retaining as much backwards-compatibility as
|
||||
possible.
|
||||
|
||||
Particular thanks must be given to Roland Schwarz, who contributed a lot of time and code to the original __boost_thread__ library,
|
||||
and who has been actively involved with the rewrite. The scheme for dividing the platform-specific implementations into separate
|
||||
directories was devised by Roland, and his input has contributed greatly to improving the quality of the current implementation.
|
||||
|
||||
Thanks also must go to Peter Dimov, Howard Hinnant, Alexander Terekhov, Chris Thomasson and others for their comments on the
|
||||
implementation details of the code.
|
||||
|
||||
[endsect]
|
||||
@@ -1,73 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.acknowledgements"
|
||||
last-revision="$Date$">
|
||||
<title>Acknowledgements</title>
|
||||
<para>William E. Kempf was the architect, designer, and implementor of
|
||||
&Boost.Thread;.</para>
|
||||
<para>Mac OS Carbon implementation written by Mac Murrett.</para>
|
||||
<para>Dave Moore provided initial submissions and further comments on the
|
||||
<code>barrier</code>
|
||||
,
|
||||
<code>thread_pool</code>
|
||||
,
|
||||
<code>read_write_mutex</code>
|
||||
,
|
||||
<code>read_write_try_mutex</code>
|
||||
and
|
||||
<code>read_write_timed_mutex</code>
|
||||
classes.</para>
|
||||
<para>Important contributions were also made by Jeremy Siek (lots of input
|
||||
on the design and on the implementation), Alexander Terekhov (lots of input
|
||||
on the Win32 implementation, especially in regards to boost::condition, as
|
||||
well as a lot of explanation of POSIX behavior), Greg Colvin (lots of input
|
||||
on the design), Paul Mclachlan, Thomas Matelich and Iain Hanson (for help
|
||||
in trying to get the build to work on other platforms), and Kevin S. Van
|
||||
Horn (for several updates/corrections to the documentation).</para>
|
||||
<para>Mike Glassford finished changes to &Boost.Thread; that were begun
|
||||
by William Kempf and moved them into the main CVS branch.
|
||||
He also addressed a number of issues that were brought up on the Boost
|
||||
developer's mailing list and provided some additions and changes to the
|
||||
read_write_mutex and related classes.</para>
|
||||
<para>The documentation was written by William E. Kempf. Beman Dawes
|
||||
provided additional documentation material and editing.
|
||||
Mike Glassford finished William Kempf's conversion of the documentation to
|
||||
BoostBook format and added a number of new sections.</para>
|
||||
<para>Discussions on the boost.org mailing list were essential in the
|
||||
development of &Boost.Thread;
|
||||
. As of August 1, 2001, participants included Alan Griffiths, Albrecht
|
||||
Fritzsche, Aleksey Gurtovoy, Alexander Terekhov, Andrew Green, Andy Sawyer,
|
||||
Asger Alstrup Nielsen, Beman Dawes, Bill Klein, Bill Rutiser, Bill Wade,
|
||||
Branko èibej, Brent Verner, Craig Henderson, Csaba Szepesvari,
|
||||
Dale Peakall, Damian Dixon, Dan Nuffer, Darryl Green, Daryle Walker, David
|
||||
Abrahams, David Allan Finch, Dejan Jelovic, Dietmar Kuehl, Douglas Gregor,
|
||||
Duncan Harris, Ed Brey, Eric Swanson, Eugene Karpachov, Fabrice Truillot,
|
||||
Frank Gerlach, Gary Powell, Gernot Neppert, Geurt Vos, Ghazi Ramadan, Greg
|
||||
Colvin, Gregory Seidman, HYS, Iain Hanson, Ian Bruntlett, J Panzer, Jeff
|
||||
Garland, Jeff Paquette, Jens Maurer, Jeremy Siek, Jesse Jones, Joe Gottman,
|
||||
John (EBo) David, John Bandela, John Maddock, John Max Skaller, John
|
||||
Panzer, Jon Jagger , Karl Nelson, Kevlin Henney, KG Chandrasekhar, Levente
|
||||
Farkas, Lie-Quan Lee, Lois Goldthwaite, Luis Pedro Coelho, Marc Girod, Mark
|
||||
A. Borgerding, Mark Rodgers, Marshall Clow, Matthew Austern, Matthew Hurd,
|
||||
Michael D. Crawford, Michael H. Cox , Mike Haller, Miki Jovanovic, Nathan
|
||||
Myers, Paul Moore, Pavel Cisler, Peter Dimov, Petr Kocmid, Philip Nash,
|
||||
Rainer Deyke, Reid Sweatman, Ross Smith, Scott McCaskill, Shalom Reich,
|
||||
Steve Cleary, Steven Kirk, Thomas Holenstein, Thomas Matelich, Trevor
|
||||
Perrin, Valentin Bonnard, Vesa Karvonen, Wayne Miller, and William
|
||||
Kempf.</para>
|
||||
<para>
|
||||
As of February 2006 Anthony Williams and Roland Schwarz took over maintainance
|
||||
and further development of the library after it has been in an orphaned state
|
||||
for a rather long period of time.
|
||||
</para>
|
||||
<para>Apologies for anyone inadvertently missed.</para>
|
||||
</section>
|
||||
|
||||
1781
doc/async_executors.qbk
Normal file
1781
doc/async_executors.qbk
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,82 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/barrier.hpp"
|
||||
last-revision="$Date$">
|
||||
<namespace name="boost">
|
||||
<class name="barrier">
|
||||
<inherit access="private">
|
||||
<type><classname>boost::noncopyable</classname></type>
|
||||
<purpose>Exposition only</purpose>
|
||||
</inherit>
|
||||
|
||||
<purpose>
|
||||
<para>An object of class <classname>barrier</classname> is a synchronization
|
||||
primitive used to cause a set of threads to wait until they each perform a
|
||||
certain function or each reach a particular point in their execution.</para>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<para>When a barrier is created, it is initialized with a thread count N.
|
||||
The first N-1 calls to <code>wait()</code> will all cause their threads to be blocked.
|
||||
The Nth call to <code>wait()</code> will allow all of the waiting threads, including
|
||||
the Nth thread, to be placed in a ready state. The Nth call will also "reset"
|
||||
the barrier such that, if an additional N+1th call is made to <code>wait()</code>,
|
||||
it will be as though this were the first call to <code>wait()</code>; in other
|
||||
words, the N+1th to 2N-1th calls to <code>wait()</code> will cause their
|
||||
threads to be blocked, and the 2Nth call to <code>wait()</code> will allow all of
|
||||
the waiting threads, including the 2Nth thread, to be placed in a ready state
|
||||
and reset the barrier. This functionality allows the same set of N threads to re-use
|
||||
a barrier object to synchronize their execution at multiple points during their
|
||||
execution.</para>
|
||||
<para>See <xref linkend="thread.glossary"/> for definitions of thread
|
||||
states <link linkend="thread.glossary.thread-state">blocked</link>
|
||||
and <link linkend="thread.glossary.thread-state">ready</link>.
|
||||
Note that "waiting" is a synonym for blocked.</para>
|
||||
</description>
|
||||
|
||||
<constructor>
|
||||
<parameter name="count">
|
||||
<paramtype>size_t</paramtype>
|
||||
</parameter>
|
||||
|
||||
<effects><simpara>Constructs a <classname>barrier</classname> object that
|
||||
will cause <code>count</code> threads to block on a call to <code>wait()</code>.
|
||||
</simpara></effects>
|
||||
</constructor>
|
||||
|
||||
<destructor>
|
||||
<effects><simpara>Destroys <code>*this</code>. If threads are still executing
|
||||
their <code>wait()</code> operations, the behavior for these threads is undefined.
|
||||
</simpara></effects>
|
||||
</destructor>
|
||||
|
||||
<method-group name="waiting">
|
||||
<method name="wait">
|
||||
<type>bool</type>
|
||||
|
||||
<effects><simpara>Wait until N threads call <code>wait()</code>, where
|
||||
N equals the <code>count</code> provided to the constructor for the
|
||||
barrier object.</simpara>
|
||||
<simpara><emphasis role="bold">Note</emphasis> that if the barrier is
|
||||
destroyed before <code>wait()</code> can return, the behavior is
|
||||
undefined.</simpara></effects>
|
||||
|
||||
<returns>Exactly one of the N threads will receive a return value
|
||||
of <code>true</code>, the others will receive a value of <code>false</code>.
|
||||
Precisely which thread receives the return value of <code>true</code> will
|
||||
be implementation-defined. Applications can use this value to designate one
|
||||
thread as a leader that will take a certain action, and the other threads
|
||||
emerging from the barrier can wait for that action to take place.</returns>
|
||||
</method>
|
||||
</method-group>
|
||||
</class>
|
||||
</namespace>
|
||||
</header>
|
||||
131
doc/barrier.qbk
Normal file
131
doc/barrier.qbk
Normal file
@@ -0,0 +1,131 @@
|
||||
[/
|
||||
(C) Copyright 2007-8 Anthony Williams.
|
||||
(C) Copyright 2013 Vicente J. Botet Escriba.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:barriers Barriers -- EXTENSION]
|
||||
|
||||
A barrier is a simple concept. Also known as a ['rendezvous], it is a synchronization point between multiple threads. The barrier is
|
||||
configured for a particular number of threads (`n`), and as threads reach the barrier they must wait until all `n` threads have
|
||||
arrived. Once the `n`-th thread has reached the barrier, all the waiting threads can proceed, and the barrier is reset.
|
||||
|
||||
[section:barrier Class `barrier`]
|
||||
|
||||
#include <boost/thread/barrier.hpp>
|
||||
|
||||
class barrier
|
||||
{
|
||||
public:
|
||||
barrier(barrier const&) = delete;
|
||||
barrier& operator=(barrier const&) = delete;
|
||||
|
||||
barrier(unsigned int count);
|
||||
template <typename F>
|
||||
barrier(unsigned int count, F&&);
|
||||
|
||||
~barrier();
|
||||
|
||||
bool wait();
|
||||
void count_down_and_wait();
|
||||
};
|
||||
|
||||
Instances of __barrier__ are not copyable or movable.
|
||||
|
||||
[section Constructor `barrier(unsigned int)`]
|
||||
|
||||
barrier(unsigned int count);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Construct a barrier for `count` threads.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error occurs.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section Constructor `barrier(unsigned int, F&&)`]
|
||||
|
||||
barrier(unsigned int count, F&& completion);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [The result type of the completion function call `completion()` is `void` or `unsigned int`.]]
|
||||
|
||||
[[Effects:] [Construct a barrier for `count` threads and a completion function `completion`.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error occurs.]]
|
||||
|
||||
]
|
||||
|
||||
|
||||
[endsect]
|
||||
[section Destructor `~barrier()`]
|
||||
|
||||
~barrier();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Precondition:] [No threads are waiting on `*this`.]]
|
||||
|
||||
[[Effects:] [Destroys `*this`.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section Member Function `wait()`]
|
||||
|
||||
bool wait();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Block until `count` threads have called `wait` or `count_down_and_wait` on `*this`. When the `count`-th thread calls `wait`, the barrier is reset and all waiting threads are unblocked.
|
||||
The reset depends on whether the barrier was constructed with a completion function or not. If there is no completion function or if the completion function result is void, the reset consists in restoring the original count. Otherwise the rest consist in assigning the result of the completion function (which must not be 0).]]
|
||||
|
||||
[[Returns:] [`true` for exactly one thread from each batch of waiting threads, `false` otherwise.]]
|
||||
|
||||
[[Throws:] [
|
||||
|
||||
- __thread_resource_error__ if an error occurs.
|
||||
|
||||
- __thread_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __thread__ object associated with the current thread of execution.
|
||||
|
||||
]]
|
||||
|
||||
[[Notes:] [`wait()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section Member Function `count_down_and_wait()`]
|
||||
|
||||
void count_down_and_wait();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Block until `count` threads have called `wait` or `count_down_and_wait` on `*this`. When the `count`-th thread calls `wait`, the barrier is reset and all waiting threads are unblocked.
|
||||
The reset depends on whether the barrier was constructed with a completion function or not. If there is no completion function or if the completion function result is void, the reset consists in restoring the original count. Otherwise the rest consist in assigning the result of the completion function (which must not be 0).]]
|
||||
|
||||
[[Throws:] [
|
||||
|
||||
- __thread_resource_error__ if an error occurs.
|
||||
|
||||
- __thread_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __thread__ object associated with the current thread of execution.
|
||||
|
||||
]]
|
||||
|
||||
[[Notes:] [`count_down_and_wait()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
[endsect]
|
||||
@@ -1,234 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<bibliography id="thread.bibliography"
|
||||
last-revision="$Date$">
|
||||
<title>Bibliography</title>
|
||||
<biblioentry id="thread.bib.AndrewsSchneider83">
|
||||
<abbrev id="thread.bib.AndrewsSchneider83.abbrev">AndrewsSchnieder83</abbrev>
|
||||
<biblioset relation="journal">
|
||||
<title>ACM Computing Surveys</title>
|
||||
<volumenum>Vol. 15</volumenum>
|
||||
<issuenum>No. 1</issuenum>
|
||||
<date>March, 1983</date>
|
||||
</biblioset>
|
||||
<biblioset relation="article">
|
||||
<authorgroup>
|
||||
<author>
|
||||
<firstname>Gregory</firstname>
|
||||
<othername>R.</othername>
|
||||
<surname>Andrews</surname>
|
||||
</author>
|
||||
<author>
|
||||
<firstname>Fred</firstname>
|
||||
<othername>B.</othername>
|
||||
<surname>Schneider</surname>
|
||||
</author>
|
||||
</authorgroup>
|
||||
<title>
|
||||
<ulink
|
||||
url="http://www.acm.org/pubs/citations/journals/surveys/1983-15-1/p3-andrews/"
|
||||
>Concepts and Notations for Concurrent Programming</ulink>
|
||||
</title>
|
||||
</biblioset>
|
||||
<para>Good general background reading. Includes descriptions of Path
|
||||
Expressions, Message Passing, and Remote Procedure Call in addition to the
|
||||
basics</para>
|
||||
</biblioentry>
|
||||
<biblioentry id="thread.bib.Boost">
|
||||
<abbrev id="thread.bib.Boost.abbrev">Boost</abbrev>
|
||||
<bibliomisc>The <emphasis>Boost</emphasis> world wide web site.
|
||||
<ulink url="http:/www.boost.org">http://www.boost.org</ulink></bibliomisc>
|
||||
<para>&Boost.Thread; is one of many Boost libraries. The Boost web
|
||||
site includes a great deal of documentation and general information which
|
||||
applies to all Boost libraries. Current copies of the libraries including
|
||||
documentation and test programs may be downloaded from the web
|
||||
site.</para>
|
||||
</biblioentry>
|
||||
<biblioentry id="thread.bib.Hansen73">
|
||||
<abbrev id="thread.bib.Hansen73.abbrev">Hansen73</abbrev>
|
||||
<biblioset relation="journal">
|
||||
<title>ACM Computing Surveys</title>
|
||||
<volumenum>Vol. 5</volumenum>
|
||||
<issuenum>No. 4</issuenum>
|
||||
<date>December, 1973</date>
|
||||
</biblioset>
|
||||
<biblioset relation="article">
|
||||
<author>0-201-63392-2
|
||||
<firstname>Per Brinch</firstname>
|
||||
<lastname>Hansen</lastname>
|
||||
</author>
|
||||
<title>
|
||||
<ulink
|
||||
url="http://www.acm.org/pubs/articles/journals/surveys/1973-5-4/p223-hansen/"
|
||||
>Concurrent Programming Concepts</ulink>
|
||||
</title>
|
||||
</biblioset>
|
||||
<para>"This paper describes the evolution of language features for
|
||||
multiprogramming from event queues and semaphores to critical regions and
|
||||
monitors." Includes analysis of why events are considered error-prone. Also
|
||||
noteworthy because of an introductory quotation from Christopher Alexander;
|
||||
Brinch Hansen was years ahead of others in recognizing pattern concepts
|
||||
applied to software, too.</para>
|
||||
</biblioentry>
|
||||
<biblioentry id="thread.bib.Butenhof97">
|
||||
<abbrev id="thread.bib.Butenhof97.abbrev">Butenhof97</abbrev>
|
||||
<title>
|
||||
<ulink url="http://cseng.aw.com/book/0,3828,0201633922,00.html"
|
||||
>Programming with POSIX Threads </ulink>
|
||||
</title>
|
||||
<author>
|
||||
<firstname>David</firstname>
|
||||
<othername>R.</othername>
|
||||
<surname>Butenhof</surname>
|
||||
</author>
|
||||
<publisher>Addison-Wesley</publisher>
|
||||
<copyright><year>1997</year></copyright>
|
||||
<isbn>ISNB: 0-201-63392-2</isbn>
|
||||
<para>This is a very readable explanation of threads and how to use
|
||||
them. Many of the insights given apply to all multithreaded programming, not
|
||||
just POSIX Threads</para>
|
||||
</biblioentry>
|
||||
<biblioentry id="thread.bib.Hoare74">
|
||||
<abbrev id="thread.bib.Hoare74.abbrev">Hoare74</abbrev>
|
||||
<biblioset relation="journal">
|
||||
<title>Communications of the ACM</title>
|
||||
<volumenum>Vol. 17</volumenum>
|
||||
<issuenum>No. 10</issuenum>
|
||||
<date>October, 1974</date>
|
||||
</biblioset>
|
||||
<biblioset relation="article">
|
||||
<title>
|
||||
<ulink url=" http://www.acm.org/classics/feb96/"
|
||||
>Monitors: An Operating System Structuring Concept</ulink>
|
||||
</title>
|
||||
<author>
|
||||
<firstname>C.A.R.</firstname>
|
||||
<surname>Hoare</surname>
|
||||
</author>
|
||||
<pagenums>549-557</pagenums>
|
||||
</biblioset>
|
||||
<para>Hoare and Brinch Hansen's work on Monitors is the basis for reliable
|
||||
multithreading patterns. This is one of the most often referenced papers in
|
||||
all of computer science, and with good reason.</para>
|
||||
</biblioentry>
|
||||
<biblioentry id="thread.bib.ISO98">
|
||||
<abbrev id="thread.bib.ISO98.abbrev">ISO98</abbrev>
|
||||
<title>
|
||||
<ulink url="http://www.ansi.org">Programming Language C++</ulink>
|
||||
</title>
|
||||
<orgname>ISO/IEC</orgname>
|
||||
<releaseinfo>14882:1998(E)</releaseinfo>
|
||||
<para>This is the official C++ Standards document. Available from the ANSI
|
||||
(American National Standards Institute) Electronic Standards Store.</para>
|
||||
</biblioentry>
|
||||
<biblioentry id="thread.bib.McDowellHelmbold89">
|
||||
<abbrev id="thread.bib.McDowellHelmbold89.abbrev">McDowellHelmbold89</abbrev>
|
||||
<biblioset relation="journal">
|
||||
<title>Communications of the ACM</title>
|
||||
<volumenum>Vol. 21</volumenum>
|
||||
<issuenum>No. 2</issuenum>
|
||||
<date>December, 1989</date>
|
||||
</biblioset>
|
||||
<biblioset>
|
||||
<author>
|
||||
<firstname>Charles</firstname>
|
||||
<othername>E.</othername>
|
||||
<surname>McDowell</surname>
|
||||
</author>
|
||||
<author>
|
||||
<firstname>David</firstname>
|
||||
<othername>P.</othername>
|
||||
<surname>Helmbold</surname>
|
||||
</author>
|
||||
<title>
|
||||
<ulink
|
||||
url="http://www.acm.org/pubs/citations/journals/surveys/1989-21-4/p593-mcdowell/"
|
||||
>Debugging Concurrent Programs</ulink>
|
||||
</title>
|
||||
</biblioset>
|
||||
<para>Identifies many of the unique failure modes and debugging difficulties
|
||||
associated with concurrent programs.</para>
|
||||
</biblioentry>
|
||||
<biblioentry id="thread.bib.SchmidtPyarali">
|
||||
<abbrev id="thread.bib.SchmidtPyarali.abbrev">SchmidtPyarali</abbrev>
|
||||
<title>
|
||||
<ulink url="http://www.cs.wustl.edu/~schmidt/win32-cv-1.html8"
|
||||
>Strategies for Implementing POSIX Condition Variables on Win32</ulink>
|
||||
</title>
|
||||
<authorgroup>
|
||||
<author>
|
||||
<firstname>Douglas</firstname>
|
||||
<othername>C.</othername>
|
||||
<surname>Schmidt</surname>
|
||||
</author>
|
||||
<author>
|
||||
<firstname>Irfan</firstname>
|
||||
<surname>Pyarali</surname>
|
||||
</author>
|
||||
</authorgroup>
|
||||
<orgname>Department of Computer Science, Washington University, St. Louis,
|
||||
Missouri</orgname>
|
||||
<para>Rationale for understanding &Boost.Thread; condition
|
||||
variables. Note that Alexander Terekhov found some bugs in the
|
||||
implementation given in this article, so pthreads-win32 and &Boost.Thread;
|
||||
are even more complicated yet.</para>
|
||||
</biblioentry>
|
||||
<biblioentry id="thread.bib.SchmidtStalRohnertBuschmann">
|
||||
<abbrev
|
||||
id="thread.bib.SchmidtStalRohnertBuschmann.abbrev">SchmidtStalRohnertBuschmann</abbrev>
|
||||
<title>
|
||||
<ulink
|
||||
url="http://www.wiley.com/Corporate/Website/Objects/Products/0,9049,104671,00.html"
|
||||
>Pattern-Oriented Architecture Volume 2</ulink>
|
||||
</title>
|
||||
<subtitle>Patterns for Concurrent and Networked Objects</subtitle>
|
||||
<titleabbrev>POSA2</titleabbrev>
|
||||
<authorgroup>
|
||||
<author>
|
||||
<firstname>Douglas</firstname>
|
||||
<othername>C.</othername>
|
||||
<surname>Schmidt</surname>
|
||||
</author>
|
||||
<author>
|
||||
<firstname>Michael</firstname>
|
||||
<lastname>Stal</lastname>
|
||||
</author>
|
||||
<author>
|
||||
<firstname>Hans</firstname>
|
||||
<surname>Rohnert</surname>
|
||||
</author>
|
||||
<author>
|
||||
<firstname>Frank</firstname>
|
||||
<surname>Buschmann</surname>
|
||||
</author>
|
||||
</authorgroup>
|
||||
<publisher>Wiley</publisher>
|
||||
<copyright><year>2000</year></copyright>
|
||||
<para>This is a very good explanation of how to apply several patterns
|
||||
useful for concurrent programming. Among the patterns documented is the
|
||||
Monitor Pattern mentioned frequently in the &Boost.Thread;
|
||||
documentation.</para>
|
||||
</biblioentry>
|
||||
<biblioentry id="thread.bib.Stroustrup">
|
||||
<abbrev id="thread.bib.Stroustrup.abbrev">Stroustrup</abbrev>
|
||||
<title>
|
||||
<ulink url="http://cseng.aw.com/book/0,3828,0201700735,00.html"
|
||||
>The C++ Programming Language</ulink>
|
||||
</title>
|
||||
<edition>Special Edition</edition>
|
||||
<publisher>Addison-Wesley</publisher>
|
||||
<copyright><year>2000</year></copyright>
|
||||
<isbn>ISBN: 0-201-70073-5</isbn>
|
||||
<para>The first book a C++ programmer should own. Note that the 3rd edition
|
||||
(and subsequent editions like the Special Edition) has been rewritten to
|
||||
cover the ISO standard language and library.</para>
|
||||
</biblioentry>
|
||||
</bibliography>
|
||||
137
doc/build.xml
137
doc/build.xml
@@ -1,137 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Copyright (c) 2007 Roland Schwarz
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.build" last-revision="$Date$">
|
||||
<title>Build</title>
|
||||
<para>
|
||||
How you build the &Boost.Thread; libraries, and how you build your own applications
|
||||
that use those libraries, are some of the most frequently asked questions. Build
|
||||
processes are difficult to deal with in a portable manner. That's one reason
|
||||
why &Boost.Thread; makes use of &Boost.Build;.
|
||||
In general you should refer to the documentation for &Boost.Build;.
|
||||
This document will only supply you with some simple usage examples for how to
|
||||
use <emphasis>bjam</emphasis> to build and test &Boost.Thread;. In addition, this document
|
||||
will try to explain the build requirements so that users may create their own
|
||||
build processes (for instance, create an IDE specific project), both for building
|
||||
and testing &Boost.Thread;, as well as for building their own projects using
|
||||
&Boost.Thread;.
|
||||
</para>
|
||||
<section id="thread.build.building">
|
||||
<title>Building the &Boost.Thread; Libraries</title>
|
||||
<para>
|
||||
Building the &Boost.Thread; Library depends on how you intend to use it. You have several options:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
Using as a <link linkend="thread.build.precompiled">precompiled</link> library, possibly
|
||||
with auto-linking, or for use from within an IDE.
|
||||
</listitem>
|
||||
<listitem>
|
||||
Use from a <link linkend="thread.build.bjam">&Boost.Build;</link> project.
|
||||
</listitem>
|
||||
<listitem>
|
||||
Using in <link linkend="thread.build.source">source</link> form.
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<section id="thread.build.precompiled">
|
||||
<title>Precompiled</title>
|
||||
<para>
|
||||
Using the &Boost.Thread; library in precompiled form is the way to go if you want to
|
||||
install the library to a standard place, from where your linker is able to resolve code
|
||||
in binary form. You also will want this option if compile time is a concern. Multiple
|
||||
variants are available, for different toolsets and build variants (debug/release).
|
||||
The library files are named <emphasis>{lead}boost_thread{build-specific-tags}.{extension}</emphasis>,
|
||||
where the build-specific-tags indicate the toolset used to build the library, whether it's
|
||||
a debug or release build, what version of &Boost; was used, etc.; and the lead and extension
|
||||
are the appropriate extensions for a dynamic link library or static library for the platform
|
||||
for which &Boost.Thread; is being built.
|
||||
For instance, a debug build of the dynamic library built for Win32 with VC++ 7.1 using Boost 1.34 would
|
||||
be named <emphasis>boost_thread-vc71-mt-gd-1_34.dll</emphasis>.
|
||||
More information on this should be available from the &Boost.Build; documentation.
|
||||
</para>
|
||||
<para>
|
||||
Building should be possible with the default configuration. If you are running into problems,
|
||||
it might be wise to adjust your local settings of &Boost.Build; though. Typically you will
|
||||
need to get your user-config.jam file to reflect your environment, i.e. used toolsets. Please
|
||||
refer to the &Boost.Build; documentation to learn how to do this.
|
||||
</para>
|
||||
<para>
|
||||
To create the libraries you need to open a command shell and change to the
|
||||
<emphasis>boost_root</emphasis> directory. From there you give the command
|
||||
<programlisting>bjam --toolset=<emphasis>mytoolset</emphasis> stage --with-thread</programlisting>
|
||||
Replace <emphasis>mytoolset</emphasis> with the name of your toolset, e.g. msvc-7.1 .
|
||||
This will compile and put the libraries into the <emphasis>stage</emphasis> directory which is just below the
|
||||
<emphasis>boost_root</emphasis> directory. &Boost.Build; by default will generate static and
|
||||
dynamic variants for debug and release.
|
||||
</para>
|
||||
<note>
|
||||
Invoking the above command without the --with-thread switch &Boost.Build; will build all of
|
||||
the Boost distribution, including &Boost.Thread;.
|
||||
</note>
|
||||
<para>
|
||||
The next step is to copy your libraries to a place where your linker is able to pick them up.
|
||||
It is also quite possible to leave them in the stage directory and instruct your IDE to take them
|
||||
from there.
|
||||
</para>
|
||||
<para>
|
||||
In your IDE you then need to add <emphasis>boost_root</emphasis>/boost to the paths where the compiler
|
||||
expects to find files to be included. For toolsets that support <emphasis>auto-linking</emphasis>
|
||||
it is not necessary to explicitly specify the name of the library to link against, it is sufficient
|
||||
to specify the path of the stage directory. Typically this is true on Windows. For gcc you need
|
||||
to specify the exact library name (including all the tags). Please don't forget that threading
|
||||
support must be turned on to be able to use the library. You should be able now to build your
|
||||
project from the IDE.
|
||||
</para>
|
||||
</section>
|
||||
<section id="thread.build.bjam">
|
||||
<title>&Boost.Build; Project</title>
|
||||
<para>
|
||||
If you have decided to use &Boost.Build; as a build environment for your application, you simply
|
||||
need to add a single line to your <emphasis>Jamroot</emphasis> file:
|
||||
<programlisting>use-project /boost : {path-to-boost-root} ;</programlisting>
|
||||
where <emphasis>{path-to-boost-root}</emphasis> needs to be replaced with the location of
|
||||
your copy of the boost tree.
|
||||
Later when you specify a component that needs to link against &Boost.Thread; you specify this
|
||||
as e.g.:
|
||||
<programlisting>exe myapp : {myappsources} /boost//thread ;</programlisting>
|
||||
and you are done.
|
||||
</para>
|
||||
</section>
|
||||
<section id="thread.build.source">
|
||||
<title>Source Form</title>
|
||||
<para>
|
||||
Of course it is also possible to use the &Boost.Thread; library in source form.
|
||||
First you need to specify the <emphasis>boost_root</emphasis>/boost directory as
|
||||
a path where your compiler expects to find files to include. It is not easy
|
||||
to isolate the &Boost.Thread; include files from the rest of the boost
|
||||
library though. You would also need to isolate every include file that the thread
|
||||
library depends on. Next you need to copy the files from
|
||||
<emphasis>boost_root</emphasis>/libs/thread/src to your project and instruct your
|
||||
build system to compile them together with your project. Please look into the
|
||||
<emphasis>Jamfile</emphasis> in <emphasis>boost_root</emphasis>/libs/thread/build
|
||||
to find out which compiler options and defines you will need to get a clean compile.
|
||||
Using the boost library in this way is the least recommended, and should only be
|
||||
considered if avoiding dependency on &Boost.Build; is a requirement. Even if so
|
||||
it might be a better option to use the library in it's precompiled form.
|
||||
Precompiled downloads are available from the boost consulting web site, or as
|
||||
part of most linux distributions.
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
<section id="thread.build.testing">
|
||||
<title>Testing the &Boost.Thread; Libraries</title>
|
||||
<para>
|
||||
To test the &Boost.Thread; libraries using &Boost.Build;, simply change to the
|
||||
directory <emphasis>boost_root</emphasis>/libs/thread/test and execute the command:
|
||||
<programlisting>bjam --toolset=<emphasis>mytoolset</emphasis> test</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
607
doc/changes.qbk
Normal file
607
doc/changes.qbk
Normal file
@@ -0,0 +1,607 @@
|
||||
[/
|
||||
(C) Copyright 2007-11 Anthony Williams.
|
||||
(C) Copyright 2011-14 Vicente J. Botet Escriba.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:changes History]
|
||||
|
||||
[heading Version 4.5.0 - boost 1.58]
|
||||
|
||||
[*Know Bugs:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2442 #2442] Application statically linked with Boost.Thread crashes when Google Desktop is installed (Windows XP)
|
||||
* [@http://svn.boost.org/trac/boost/ticket/3926 #3926] thread_specific_ptr + dlopen library causes a SIGSEGV.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4833 #4833] MinGW/test_tss_lib: Support of automatic tss cleanup for native threading API not available
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7319 #7319] Take care of c++std-lib-32966 issue
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8600 #8600] wait_for_any hangs, if called with multiple copies of shared_future referencing same task
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9118 #9118] Seg fault on thread join when llvm and libc++ are used
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9309 #9309] test_latch fails often on clang-darwin-tot11
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9310 #9310] test_4648_lib fails on clang-darwin-asan11
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9311 #9311] ex_lambda_future fails on msvc-11.0
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10537 #10537] Application crash on throw exception
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10651 #10651] boost::thread leaks memory when using the MinGW compiler
|
||||
|
||||
Please take a look at [@https://svn.boost.org/trac/boost/query?status=assigned&status=new&status=reopened&component=thread&type=!Feature+Requests&col=id&col=summary&order=id thread Know Bugs] to see the current state.
|
||||
|
||||
Please take a look at [@http://www.boost.org/development/tests/master/developer/thread.html thread trunk regression test] to see the last snapshot.
|
||||
|
||||
[*Sever limitations:]
|
||||
|
||||
There are some severe bugs that prevent the use of the library on concrete contexts, in particular:
|
||||
|
||||
* on thread specific storage that prevent the library to be used with dynamic libraries,
|
||||
|
||||
[*New Experimental Features:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9600 #9600] Async: Add task_region
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10611 #10611] Add emplace promise::set_value and emplace make_ready_future
|
||||
|
||||
[*Fixed Bugs:]
|
||||
|
||||
|
||||
[heading Version 4.4.0 - boost 1.57]
|
||||
|
||||
[*Know Bugs:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2442 #2442] Application statically linked with Boost.Thread crashes when Google Desktop is installed (Windows XP)
|
||||
* [@http://svn.boost.org/trac/boost/ticket/3926 #3926] thread_specific_ptr + dlopen library causes a SIGSEGV.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4833 #4833] MinGW/test_tss_lib: Support of automatic tss cleanup for native threading API not available
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7319 #7319] Take care of c++std-lib-32966 issue
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8600 #8600] wait_for_any hangs, if called with multiple copies of shared_future referencing same task
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9118 #9118] Seg fault on thread join when llvm and libc++ are used
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9309 #9309] test_latch fails often on clang-darwin-tot11
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9310 #9310] test_4648_lib fails on clang-darwin-asan11
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9311 #9311] ex_lambda_future fails on msvc-11.0
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10537 #10537] Application crash on throw exception
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10651 #10651] boost::thread leaks memory when using the MinGW compiler
|
||||
|
||||
Please take a look at [@https://svn.boost.org/trac/boost/query?status=assigned&status=new&status=reopened&component=thread&type=!Feature+Requests&col=id&col=summary&order=id thread Know Bugs] to see the current state.
|
||||
|
||||
Please take a look at [@http://www.boost.org/development/tests/master/developer/thread.html thread trunk regression test] to see the last snapshot.
|
||||
|
||||
[*Sever limitations:]
|
||||
|
||||
There are some severe bugs that prevent the use of the library on concrete contexts, in particular:
|
||||
|
||||
* on thread specific storage that prevent the library to be used with dynamic libraries,
|
||||
|
||||
[*New Experimental Features:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6227 #6227] Synchro: Use of variadic templates on Generic Locking Algorithms on compilers providing them
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10298 #10298] Synchro: Added queue views.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10300 #10300] Async: Added generic_executor_ref.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10552 #10552] Add make_valid_future
|
||||
|
||||
[*Fixed Bugs:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6782 #6782] call_once uses incorrect barrier intrinsic on Visual Studio
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6787 #6787] boost::thread::sleep() hangs if system time is rolled back
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7665 #7665] this_thread::sleep_for no longer uses steady_clock in thread
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9307 #9307] future::fallback_to assert with ERRORRRRR boost: mutex lock failed in pthread_mutex_lock: Invalid argument
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9308 #9308] future::async fails with terminate called throwing an exception when called with a lambda - clang-darwin-asan11
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9310 #9310] test_4648_lib fails on clang-darwin-asan11
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9425 #9425] Boost promise & future does not use supplied allocator for value storage
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9558 #9558] future continuations unit test hangs in get()/pthread_cond_wait() on Mac 10.7/32-bit/x86/darwin-4.2.1
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9787 #9787] [windows] Small duration value passed down to basic_timed_mutex::try_lock_until and condition_variable::wait_until can cause infinite or near infinite wait for win32
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9880 #9880] [windows] boost::condition_variable.timed_wait() exception if system time < 1970
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10159 #10159] GCC 4.4 error sorry, unimplemented
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10196 #10196] thread_specific_ptr does not support void*
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10296 #10296] Boost.Thread 1.56 rc1 does not compile on Mingw
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10297 #10297] Boost.Thread 1.56 rc1 hangs when built with clang on armhf
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10340 #10340] No boost::promise<T>::set_value(const T&) overload present in C++03 mode
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10425 #10425] Missing documentation for when_all/when_any.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10426 #10426] Take in account the deferred futures in when_all.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10427 #10427] Take in account the deferred and ready futures in when_any.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10428 #10428] Adapt to new unique_ptr interface in Boost.Move
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10465 #10465] Missing implementation of when_all/when_any when the result is a tuple.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10476 #10476] classes using BOOST_THREAD_MOVABLE_ONLY<T> dont satisfy is_copy_constructible<T>::value == false
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10478 #10478] Data race in boost/thread/future.hpp
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10529 #10529] The pthread/condition_variable_any constructor reports incorrect error code for pthread_cond_init
|
||||
* [@http://svn.boost.org/trac/boost/ticket/10563 #10563] shared_future<R>::then should be const
|
||||
|
||||
|
||||
[heading Version 4.3.0 - boost 1.56]
|
||||
|
||||
[*Know Bugs:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2442 #2442] Application statically linked with Boost.Thread crashes when Google Desktop is installed (Windows XP)
|
||||
* [@http://svn.boost.org/trac/boost/ticket/3926 #3926] thread_specific_ptr + dlopen library causes a SIGSEGV.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4833 #4833] MinGW/test_tss_lib: Support of automatic tss cleanup for native threading API not available
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6782 #6782] call_once uses incorrect barrier intrinsic on Visual Studio
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7319 #7319] Take care of c++std-lib-32966 issue
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8600 #8600] wait_for_any hangs, if called with multiple copies of shared_future referencing same task
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9307 #9307] future::fallback_to assert with ERRORRRRR boost: mutex lock failed in pthread_mutex_lock: Invalid argument
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9308 #9308] future::async fails with terminate called throwing an exception when called with a lambda - clang-darwin-asan11
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9310 #9310] test_4648_lib fails on clang-darwin-asan11
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9311 #9311] ex_lambda_future fails on msvc-11.0
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9425 #9425] Boost promise & future does not use supplied allocator for value storage
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9558 #9558] future continuations unit test hangs in get()/pthread_cond_wait() on Mac 10.7/32-bit/x86/darwin-4.2.1
|
||||
|
||||
Please take a look at [@https://svn.boost.org/trac/boost/query?status=assigned&status=new&status=reopened&component=thread&type=!Feature+Requests&col=id&col=summary&order=id thread Know Bugs] to see the current state.
|
||||
|
||||
Please take a look at [@http://www.boost.org/development/tests/master/developer/thread.html thread trunk regression test] to see the last snapshot.
|
||||
|
||||
|
||||
[*Sever limitations:]
|
||||
|
||||
There are some severe bugs that prevent the use of the library on concrete contexts, in particular:
|
||||
|
||||
* on thread specific storage that prevent the library to be used with dynamic libraries,
|
||||
* The experimental features of boost::future have some severe holes that make the program crash unexpectedly.
|
||||
|
||||
[*New Experimental Features:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7446 #7446] Async: Add when_any.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7447 #7447] Async: Add when_all.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7448 #7448] Async: Add async taking a scheduler parameter.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8274 #8274] Synchro: Add concurrent queue
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8518 #8518] Synchro: Add a latch class.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8513 #8513] Async: Add a basic thread_pool executor.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8516 #8516] Async: Add future/shared_future::then taking a scheduler as parameter.
|
||||
|
||||
[*Fixed Bugs:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8070 #8070] prefer GetTickCount64 over GetTickCount
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9333 #9333] ex_scoped_thread compile fails on msvc-12.0
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9366 #9366] async(Executor, ...) fails to compile with msvc-10,11,12
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9402 #9402] test_excutor regression on msvc-10,11,12
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9404 #9404] ex_make_future regression error
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9471 #9471] Synchronization documentation nits
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9535 #9535] Missing exception safety might result in crash
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9618 #9618] try_join_for problem: program is not terminate.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9673 #9673] thread compilation with MingW/gcc on Windows gives errors
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9708 #9708] boost::condition_variable::timed_wait unexpectedly wakes up while should wait infinite
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9711 #9711] future continuation called twice
|
||||
|
||||
[heading Version 4.2.0 - boost 1.55]
|
||||
|
||||
[*Know Bugs:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2442 #2442] Application statically linked with Boost.Thread crashes when Google Desktop is installed (Windows XP)
|
||||
* [@http://svn.boost.org/trac/boost/ticket/3926 #3926] thread_specific_ptr + dlopen library causes a SIGSEGV.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4833 #4833] MinGW/test_tss_lib: Support of automatic tss cleanup for native threading API not available
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6782 #6782] call_once uses incorrect barrier intrinsic on Visual Studio
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7319 #7319] Take care of c++std-lib-32966 issue
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8600 #8600] wait_for_any hangs, if called with multiple copies of shared_future referencing same task
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9307 #9307] future::fallback_to assert with ERRORRRRR boost: mutex lock failed in pthread_mutex_lock: Invalid argument
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9308 #9308] future::async fails with terminate called throwing an exception when called with a lambda - clang-darwin-asan11
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9311 #9311] ex_lambda_future fails on msvc-11.0
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9310 #9310] test_4648_lib fails on clang-darwin-asan11
|
||||
|
||||
Please take a look at [@https://svn.boost.org/trac/boost/query?status=assigned&status=new&status=reopened&component=thread&type=!Feature+Requests&col=id&col=summary&order=id thread trunk regression test] to see the current state.
|
||||
|
||||
[*Sever limitations:]
|
||||
|
||||
There are some severe bugs that prevent the use of the library on concrete contexts, in particular:
|
||||
|
||||
* on thread specific storage that prevent the library to be used with dynamic libraries,
|
||||
* The experimental features of boost::future have some severe holes that make the program crash unexpectedly.
|
||||
|
||||
[*New Features:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8519 #8519] Synchro: Update class barrier with a completion function.
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8515 #8515] Async: Add shared_future::then.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8519 #8519] Synchro: Update class barrier with a completion function
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8615 #8615] Async: Replace make_future/make_shared_future by make_ready_future.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8627 #8627] Async: Add future<>::unwrap and unwrapping constructor.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8677 #8677] Async: Add future<>::get_or.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8678 #8678] Async: Add future<>::fallback_to.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8891 #8891] upgrade_to_unique_lock: missing mutex() function.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8955 #8955] Request for more efficient way to get exception_ptr from future.
|
||||
|
||||
[*Fixed Bugs:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7461 #7461] detail::win32::ReleaseSemaphore may be called with count_to_release equal to 0
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8070 #8070] prefer GetTickCount64 over GetTickCount
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8768 #8768] win32 condition_variable::wait_until infinite wait in rare cases.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8817 #8817] Boost Thread Windows CE _createthreadex handling breaks mingw w64.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8943 #8943] Failed to compile code using boost::call_once with Intel C++ Composer XE 2013 on Windows.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8931 #8931] Typos in external_locking reference.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9029 #9029] Misprint in documentation.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9037 #9037] gcc -Wshadow gives warnings in condition_variable{,_fwd}.hpp.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9041 #9041] Boost.Thread DSO's may need to link with Boost.Atomic.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9048 #9048] boost::scoped_thread useless ctor with variadic template arguments.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9079 #9079] Condition variable will wait forever for some timepoint values (Win).
|
||||
|
||||
[heading Version 4.1.0 - boost 1.54]
|
||||
|
||||
[*New Features:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7285 #7285] C++11 compliance: Allow to pass movable arguments for call_once.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7445 #7445] Async: Add future<>.then
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7449 #7449] Synchro: Add a synchronized value class
|
||||
|
||||
[*Fixed Bugs:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4878 #4878] MinGW 4.5.0 undefined reference to bool interruptible_wait(detail::win32::handle handle_to_wait_for,detail::t imeout target_time).
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4882 #4882] Win32 shared_mutex does not handle timeouts correctly.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5752 #5752] boost::call_once() is unreliable on some platforms
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6652 #6652] Boost.Thread shared_mutex.hpp:50:99: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6843 #6843] [Intel C++] Compile Errors with '#include <atomic>'
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6966 #6966] future boost::future_category inconsistent dll linkage
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7720 #7720] exception lock_error while intensive locking/unlocking of mutex
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7755 #7755] Thread: deadlock with shared_mutex on Windows
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7980 #7980] Build error: msvc-11.0 and BOOST_THREAD_DONT_USE_DATETIME
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7982 #7982] pthread_delay_np() parm compile error on AIX
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8027 #8027] thread library fails to compile with Visual Studio 2003
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8070 #8070] prefer GetTickCount64 over GetTickCount
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8136 #8136] boost::this_thread::sleep_for() sleeps longer than it should in Windows
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8212 #8212] Boost thread compilation error on Solaris 10
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8237 #8237] fix documentation for 'thread_group'
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8239 #8239] barrier::wait() not marked as interruption_point
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8323 #8323] boost::thread::try_join_for/try_join_until may block indefinitely due to a combination of problems in Boost.Thread and Boost.Chrono
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8337 #8337] The internal representation of "std::string(this->code()->message())" escapes, but is destroyed when it exits scope.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8371 #8371] C++11 once_flag enabled when constexpr is not available
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8422 #8422] Assertion in win32::WaitForSingleObject()
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8443 #8443] Header file inclusion order may cause crashes
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8451 #8451] Missing documented function 'boost::scoped_thread::joinable'
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8458 #8458] -DBOOST_THREAD_DONT_USE_CHRONO in thread.obj.rsp but not explicitly set
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8530 #8530] [Coverity] Unused variable thread_handle, uninitialized variable cond_mutex in thread/pthread/thread_data.hpp
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8550 #8550] static linking of Boost.Thread with an MFC-Dll
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8576 #8576] "sur parolle" should be "sur parole".
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8596 #8596] With C++0x enabled, boost::packaged_task stores a reference to function objects, instead of a copy.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8626 #8626] Reintroduce BOOST_VERIFY on pthread_mutex_destroy return type
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8645 #8645] Typo in Strict lock definition
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8671 #8671] promise: set_..._at_thread_exit
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8672 #8672] future<>::then(void()) doesn't works
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8674 #8674] Futures as local named objects can't be returned with implicit move.
|
||||
|
||||
[heading Version 4.0.0 - boost 1.53]
|
||||
|
||||
[/
|
||||
[*Breaking changes:]
|
||||
|
||||
[warning
|
||||
BOOST_THREAD_VERSION==3 by default since Boost 1.53. So that all the deprecated features since 1.50 are not included by default. You can change this by setting the appropriated define (see Configuration section).
|
||||
]
|
||||
]
|
||||
|
||||
[*Deprecated features:]
|
||||
|
||||
[warning Deprecated features since boost 1.53 will be available only until boost 1.58.]
|
||||
|
||||
* C++11 compliance: packaged_task<R> is deprecated, use instead packaged_task<R()>.
|
||||
See BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK and BOOST_THREAD_DONT_PROVIDE_SIGNATURE_PACKAGED_TASK
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7537 #7537] deprecate Mutex::scoped_lock and scoped_try_lock and boost::condition
|
||||
|
||||
[*New Features:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6270 #6270] c++11 compliance: Add thread constructor from movable callable and movable arguments
|
||||
Provided when BOOST_THREAD_PROVIDES_VARIADIC_THREAD is defined (Default value from Boost 1.55):
|
||||
See BOOST_THREAD_PROVIDES_VARIADIC_THREAD and BOOST_THREAD_DONT_PROVIDE_VARIADIC_THREAD.
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7279 #7279] C++11 compliance: Add noexcept in system related functions
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7280 #7280] C++11 compliance: Add promise::...at_thread_exit functions
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7281 #7281] C++11 compliance: Add ArgTypes to packaged_task template.
|
||||
Provided when BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK is defined (Default value from Boost 1.55).
|
||||
See BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK and BOOST_THREAD_DONT_PROVIDE_SIGNATURE_PACKAGED_TASK.
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7282 #7282] C++11 compliance: Add packaged_task::make_ready_at_thread_exit function
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7285 #7285] C++11 compliance: Allow to pass movable arguments for call_once
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7412 #7412] C++11 compliance: Add async from movable callable and movable arguments
|
||||
Provided when BOOST_THREAD_PROVIDES_VARIADIC_THREAD and BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK are defined (Default value from Boost 1.55):
|
||||
See BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK and BOOST_THREAD_DONT_PROVIDE_SIGNATURE_PACKAGED_TASK, BOOST_THREAD_PROVIDES_VARIADIC_THREAD and BOOST_THREAD_DONT_PROVIDE_VARIADIC_THREAD.
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7413 #7413] C++11 compliance: Add async when the launch policy is deferred.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7414 #7414] C++11 compliance: future::get post-condition should be valid()==false.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7422 #7422] Provide a condition variable with zero-overhead performance penality.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7414 #7444] Async: Add make_future/make_shared_future.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7540 #7540] Threads: Add a helper class that join a thread on destruction.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7541 #7541] Threads: Add a thread wrapper class that joins on destruction.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7575 #7575] C++11 compliance: A future created by async should "join" in the destructor.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7587 #7587] Synchro: Add strict_lock and nested_strict_lock.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7588 #7588] Synchro: Split the locks.hpp in several files to limit dependencies.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7590 #7590] Synchro: Add lockable concept checkers based on Boost.ConceptCheck.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7591 #7591] Add lockable traits that can be used with enable_if.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7592 #7592] Synchro: Add a null_mutex that is a no-op and that is a model of UpgardeLockable.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7593 #7593] Synchro: Add a externally_locked class.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7590 #7594] Threads: Allow to disable thread interruptions.
|
||||
|
||||
[*Fixed Bugs:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5752 #5752] boost::call_once() is unreliable on some platforms
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7464 #7464] BOOST_TEST(n_alive == 1); fails due to race condition in a regression test tool.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7657 #7657] Serious performance and memory consumption hit if condition_variable methods condition notify_one or notify_all is used repeatedly.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7665 #7665] this_thread::sleep_for no longer uses steady_clock in thread.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7668 #7668] thread_group::join_all() should check whether its threads are joinable.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7669 #7669] thread_group::join_all() should catch resource_deadlock_would_occur.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7671 #7671] Error including boost/thread.hpp header on iOS.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7672 #7672] lockable_traits.hpp syntax error: "defined" token misspelled.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7798 #7798] boost::future set_wait_callback thread safety issues.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7808 #7808] Incorrect description of effects for this_thread::sleep_for and this_thread::sleep_until.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7812 #7812] Returns: cv_status::no_timeout if the call is returning because the time period specified by rel_time has elapsed, cv_status::timeout otherwise.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7874 #7874] compile warning: thread.hpp:342: warning: type attributes are honored only at type definition.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7875 #7875] BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED should not be enabled by default.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7882 #7882] wrong exception text from condition_variable::wait(unique_lock<mutex>&).
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7890 #7890] thread::do_try_join_until() is missing a return type.
|
||||
|
||||
|
||||
|
||||
[heading Version 3.1.0 - boost 1.52]
|
||||
|
||||
Deprecated Features:
|
||||
|
||||
Deprecated features since boost 1.50 available only until boost 1.55:
|
||||
|
||||
These deprecated features will be provided by default up to boost 1.52. If you don't want to include the deprecated features you could define BOOST_THREAD_DONT_PROVIDE_DEPRECATED_FEATURES_SINCE_V3_0_0. Since 1.53 these features will not be included any more by default. Since this version, if you want to include the deprecated features yet you could define BOOST_THREAD_PROVIDE_DEPRECATED_FEATURES_SINCE_V3_0_0. These deprecated features will be only available until boost 1.55, that is you have yet 1 year to move to the new features.
|
||||
|
||||
* Time related functions don't using the Boost.Chrono library, use the chrono overloads instead.
|
||||
|
||||
Breaking changes when BOOST_THREAD_VERSION==3 (Default value since Boost 1.53):
|
||||
|
||||
There are some new features which share the same interface but with different behavior. These breaking features are provided by default when BOOST_THREAD_VERSION is 3, but the user can however choose the version 2 behavior by defining the corresponding macro. As for the deprecated features, these broken features will be only available until boost 1.55.
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6229 #6229] Rename the unique_future to future following the c++11.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6266 #6266] Breaking change: thread destructor should call terminate if joinable.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6269 #6269] Breaking change: thread move assignment should call terminate if joinable.
|
||||
|
||||
New Features:
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2361 #2361] thread_specific_ptr: document nature of the key, complexity and rationale.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4710 #4710] C++11 compliance: Missing async().
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7283 #7283] C++11 compliance: Add notify_all_at_thread_exit.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7345 #7345] C++11 compliance: Add noexcept to recursive mutex try_lock.
|
||||
|
||||
Fixed Bugs:
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2797 #2797] Two problems with thread_specific_ptr.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5274 #5274] failed to compile future.hpp with stlport 5.1.5 under msvc8.1, because of undefined class.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5431 #5431] compile error in Windows CE 6.0(interlocked).
|
||||
[/* [@http://svn.boost.org/trac/boost/ticket/5752 #5752] boost::call_once() is unreliable on some platforms.]
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5696 #5696] win32 detail::set_tss_data does nothing when tss_cleanup_function is NULL.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6931 #6931] mutex waits forwever with Intel C++ Compiler XE 12.1.5.344 Build 20120612
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7045 #7045] Thread library does not automatically compile date_time.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7173 #7173] wrong function name interrupt_point().
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7200 #7200] Unable to build boost.thread modularized.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7220 #7220] gcc 4.6.2 warns about inline+dllimport functions.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7238 #7238] this_thread::sleep_for() does not respond to interrupt().
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7245 #7245] Minor typos on documentation related to version 3.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7272 #7272] win32/thread_primitives.hpp: (Unneccessary) Warning.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7284 #7284] Clarify that there is no access priority between lock and shared_lock on shared mutex.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7329 #7329] boost/thread/future.hpp does not compile on HPUX.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7336 #7336] BOOST_THREAD_DONT_USE_SYSTEM doesn't work.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7329 #7349] packaged_task holds reference to temporary.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7350 #7350] allocator_destructor does not destroy object
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7360 #7360] Memory leak in pthread implementation of boost::thread_specific_ptr
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7370 #7370] Boost.Thread documentation
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7438 #7438] Segmentation fault in test_once regression test in group.join_all();
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7461 #7461] detail::win32::ReleaseSemaphore may be called with count_to_release equal to 0
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7499 #7499] call_once doesn't call even once
|
||||
|
||||
|
||||
[heading Version 3.0.1 - boost 1.51]
|
||||
|
||||
Deprecated Features:
|
||||
|
||||
Deprecated features since boost 1.50 available only until boost 1.55:
|
||||
|
||||
These deprecated features will be provided by default up to boost 1.52. If you don't want to include the deprecated features you could define BOOST_THREAD_DONT_PROVIDE_DEPRECATED_FEATURES_SINCE_V3_0_0. Since 1.53 these features will not be included any more by default. Since this version, if you want to include the deprecated features yet you could define BOOST_THREAD_PROVIDE_DEPRECATED_FEATURES_SINCE_V3_0_0. These deprecated features will be only available until boost 1.55, that is you have 1 year and a half to move to the new features.
|
||||
|
||||
* Time related functions don't using the Boost.Chrono library, use the chrono overloads instead.
|
||||
|
||||
Breaking changes when BOOST_THREAD_VERSION==3:
|
||||
|
||||
There are some new features which share the same interface but with different behavior. These breaking features are provided by default when BOOST_THREAD_VERSION is 3, but the user can however choose the version 2 behavior by defining the corresponding macro. As for the deprecated features, these broken features will be only available until boost 1.55.
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6229 #6229] Rename the unique_future to future following the c++11.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6266 #6266] Breaking change: thread destructor should call terminate if joinable.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6269 #6269] Breaking change: thread move assignment should call terminate if joinable.
|
||||
|
||||
|
||||
Fixed Bugs:
|
||||
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4258 #4258] Linking with boost thread does not work on mingw/gcc 4.5.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4885 #4885] Access violation in set_tss_data at process exit due to invalid assumption about TlsAlloc.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6931 #6931] mutex waits forwever with Intel Compiler and /debug:parallel
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7044 #7044] boost 1.50.0 header missing.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7052 #7052] Thread: BOOST_THREAD_PROVIDES_DEPRECATED_FEATURES_SINCE_V3_0_0 only masks thread::operator==, thread::operator!= forward declarations, not definitions.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7066 #7066] An attempt to fix current_thread_tls_key static initialization order.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7074 #7074] Multiply defined symbol boost::allocator_arg.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7078 #7078] Trivial 64-bit warning fix on Windows for thread attribute stack size
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7089 #7089] BOOST_THREAD_WAIT_BUG limits functionality without solving anything
|
||||
|
||||
[/
|
||||
#6787 boost::thread::sleep() hangs if system time is rolled back
|
||||
#7045 Thread library does not automatically compile date_time
|
||||
]
|
||||
|
||||
[heading Version 3.0.0 - boost 1.50]
|
||||
|
||||
Breaking changes when BOOST_THREAD_VERSION==3:
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6229 #6229] Breaking change: Rename the unique_future to future following the c++11.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6266 #6266] Breaking change: thread destructor should call terminate if joinable.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6269 #6269] Breaking change: thread move assignment should call terminate if joinable.
|
||||
|
||||
New Features:
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/1850 #1850] Request for unlock_guard to compliment lock_guard.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2637 #2637] Request for shared_mutex duration timed_lock and timed_lock_shared.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2741 #2741] Proposal to manage portable and non portable thread attributes.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/3567 #3567] Request for shared_lock_guard.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6194 #6194] Adapt to Boost.Move.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6195 #6195] c++11 compliance: Provide the standard time related interface using Boost.Chrono.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6217 #6217] Enhance Boost.Thread shared mutex interface following Howard Hinnant proposal.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6224 #6224] c++11 compliance: Add the use of standard noexcept on compilers supporting them.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6225 #6225] Add the use of standard =delete defaulted operations on compilers supporting them.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6226 #6226] c++11 compliance: Add explicit bool conversion from locks.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6228 #6228] Add promise constructor with allocator following the standard c++11.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6230 #6230] c++11 compliance: Follows the exception reporting mechanism as defined in the c++11.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6231 #6231] Add BasicLockable requirements in the documentation to follow c++11.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6272 #6272] c++11 compliance: Add thread::id hash specialization.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6273 #6273] c++11 compliance: Add cv_status enum class and use it on the conditions wait functions.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6342 #6342] c++11 compliance: Adapt the one_flag to the c++11 interface.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6671 #6671] upgrade_lock: missing mutex and release functions.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6672 #6672] upgrade_lock:: missing constructors from time related types.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6675 #6675] upgrade_lock:: missing non-member swap.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6676 #6676] lock conversion should be explicit.
|
||||
* Added missing packaged_task::result_type and packaged_task:: constructor with allocator.
|
||||
* Added packaged_task::reset()
|
||||
|
||||
|
||||
Fixed Bugs:
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2380 #2380] boost::move from lvalue does not work with gcc.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2430 #2430] shared_mutex for win32 doesn't have timed_lock_upgrade.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2575 #2575] Bug- Boost 1.36.0 on Itanium platform.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/3160 #3160] Duplicate tutorial code in boost::thread.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4345 #4345] thread::id and joining problem with cascade of threads.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4521 #4521] Error using boost::move on packaged_task (MSVC 10).
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4711 #4711] Must use implementation details to return move-only types.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4921 #4921] BOOST_THREAD_USE_DLL and BOOST_THREAD_USE_LIB are crucial and need to be documented.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5013 #5013] documentation: boost::thread: pthreas_exit causes terminate().
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5173 #5173] boost::this_thread::get_id is very slow.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5351 #5351] interrupt a future get boost::unknown_exception.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5516 #5516] Upgrade lock is not acquired when previous upgrade lock releases if another read lock is present.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5990 #5990] shared_future<T>::get() has wrong return type.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6174 #6174] packaged_task doesn't correctly handle moving results.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6222 #6222] Compile error with SunStudio: unique_future move.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6354 #6354] PGI: Compiler threading support is not turned on.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6673 #6673] shared_lock: move assign doesn't works with c++11.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6674 #6674] shared_mutex: try_lock_upgrade_until doesn't works.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6908 #6908] Compile error due to unprotected definitions of _WIN32_WINNT and WINVER.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6940 #6940] TIME_UTC is a macro in C11.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6959 #6959] call of abs is ambiguous.
|
||||
* Fix issue signaled on the ML with task_object(task_object const&) in presence of task_object(task_object &&)
|
||||
|
||||
|
||||
|
||||
[heading Version 2.1.1 - boost 1.49]
|
||||
|
||||
Fixed Bugs:
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2309 #2309] Lack of g++ symbol visibility support in Boost.Thread.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2639 #2639] documentation should be extended(defer_lock, try_to_lock, ...).
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/3639 #3639] Boost.Thread doesn't build with Sun-5.9 on Linux.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/3762 #3762] Thread can't be compiled with winscw (Codewarrior by Nokia).
|
||||
* [@http://svn.boost.org/trac/boost/ticket/3885 #3885] document about mix usage of boost.thread and native thread api.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/3975 #3975] Incorrect precondition for promise::set_wait_callback().
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4048 #4048] thread::id formatting involves locale
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4315 #4315] gcc 4.4 Warning: inline ... declared as dllimport: attribute ignored.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4480 #4480] OpenVMS patches for compiler issues workarounds.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4819 #4819] boost.thread's documentation misprints.
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5423 #5423] thread issues with C++0x.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5617 #5617] boost::thread::id copy ctor.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5739 #5739] set-but-not-used warnings with gcc-4.6.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5826 #5826] threads.cpp: resource leak on threads creation failure.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5839 #5839] thread.cpp: ThreadProxy leaks on exceptions.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5859 #5859] win32 shared_mutex constructor leaks on exceptions.
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6100 #6100] Compute hardware_concurrency() using get_nprocs() on GLIBC systems.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6168 #6168] recursive_mutex is using wrong config symbol (possible typo).
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6175 #6175] Compile error with SunStudio.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6200 #6200] patch to have condition_variable and mutex error better handle EINTR.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6207 #6207] shared_lock swap compiler error on clang 3.0 c++11.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6208 #6208] try_lock_wrapper swap compiler error on clang 3.0 c++11.
|
||||
|
||||
[heading Version 2.1.0 - Changes since boost 1.40]
|
||||
|
||||
The 1.41.0 release of Boost adds futures to the thread library. There are also a few minor changes.
|
||||
|
||||
[heading Changes since boost 1.35]
|
||||
|
||||
The 1.36.0 release of Boost includes a few new features in the thread library:
|
||||
|
||||
* New generic __lock_multiple_ref__ and __try_lock_multiple_ref__ functions for locking multiple mutexes at once.
|
||||
|
||||
* Rvalue reference support for move semantics where the compilers supports it.
|
||||
|
||||
* A few bugs fixed and missing functions added (including the serious win32 condition variable bug).
|
||||
|
||||
* `scoped_try_lock` types are now backwards-compatible with Boost 1.34.0 and previous releases.
|
||||
|
||||
* Support for passing function arguments to the thread function by supplying additional arguments to the __thread__ constructor.
|
||||
|
||||
* Backwards-compatibility overloads added for `timed_lock` and `timed_wait` functions to allow use of `xtime` for timeouts.
|
||||
|
||||
[heading Version 2.0.0 - Changes since boost 1.34]
|
||||
|
||||
Almost every line of code in __boost_thread__ has been changed since the 1.34 release of boost. However, most of the interface
|
||||
changes have been extensions, so the new code is largely backwards-compatible with the old code. The new features and breaking
|
||||
changes are described below.
|
||||
|
||||
[heading New Features]
|
||||
|
||||
* Instances of __thread__ and of the various lock types are now movable.
|
||||
|
||||
* Threads can be interrupted at __interruption_points__.
|
||||
|
||||
* Condition variables can now be used with any type that implements the __lockable_concept__, through the use of
|
||||
`boost::condition_variable_any` (`boost::condition` is a `typedef` to `boost::condition_variable_any`, provided for backwards
|
||||
compatibility). `boost::condition_variable` is provided as an optimization, and will only work with
|
||||
`boost::unique_lock<boost::mutex>` (`boost::mutex::scoped_lock`).
|
||||
|
||||
* Thread IDs are separated from __thread__, so a thread can obtain it's own ID (using `boost::this_thread::get_id()`), and IDs can
|
||||
be used as keys in associative containers, as they have the full set of comparison operators.
|
||||
|
||||
* Timeouts are now implemented using the Boost DateTime library, through a typedef `boost::system_time` for absolute timeouts, and
|
||||
with support for relative timeouts in many cases. `boost::xtime` is supported for backwards compatibility only.
|
||||
|
||||
* Locks are implemented as publicly accessible templates `boost::lock_guard`, `boost::unique_lock`, `boost::shared_lock`, and
|
||||
`boost::upgrade_lock`, which are templated on the type of the mutex. The __lockable_concept__ has been extended to include publicly
|
||||
available __lock_ref__ and __unlock_ref__ member functions, which are used by the lock types.
|
||||
|
||||
[heading Breaking Changes]
|
||||
|
||||
The list below should cover all changes to the public interface which break backwards compatibility.
|
||||
|
||||
* __try_mutex__ has been removed, and the functionality subsumed into __mutex__. __try_mutex__ is left as a `typedef`,
|
||||
but is no longer a separate class.
|
||||
|
||||
* __recursive_try_mutex__ has been removed, and the functionality subsumed into
|
||||
__recursive_mutex__. __recursive_try_mutex__ is left as a `typedef`, but is no longer a separate class.
|
||||
|
||||
* `boost::detail::thread::lock_ops` has been removed. Code that relies on the `lock_ops` implementation detail will no longer work,
|
||||
as this has been removed, as it is no longer necessary now that mutex types now have public __lock_ref__ and __unlock_ref__ member
|
||||
functions.
|
||||
|
||||
* `scoped_lock` constructors with a second parameter of type `bool` are no longer provided. With previous boost releases,
|
||||
``boost::mutex::scoped_lock some_lock(some_mutex,false);`` could be used to create a lock object that was associated with a mutex,
|
||||
but did not lock it on construction. This facility has now been replaced with the constructor that takes a
|
||||
`boost::defer_lock_type` as the second parameter: ``boost::mutex::scoped_lock some_lock(some_mutex,boost::defer_lock);``
|
||||
|
||||
* The `locked()` member function of the `scoped_lock` types has been renamed to __owns_lock_ref__.
|
||||
|
||||
* You can no longer obtain a __thread__ instance representing the current thread: a default-constructed __thread__ object is not
|
||||
associated with any thread. The only use for such a thread object was to support the comparison operators: this functionality has
|
||||
been moved to __thread_id__.
|
||||
|
||||
* The broken `boost::read_write_mutex` has been replaced with __shared_mutex__.
|
||||
|
||||
* __mutex__ is now never recursive. For Boost releases prior to 1.35 __mutex__ was recursive on Windows and not on POSIX platforms.
|
||||
|
||||
* When using a __recursive_mutex__ with a call to [cond_any_wait_link `boost::condition_variable_any::wait()`], the mutex is only
|
||||
unlocked one level, and not completely. This prior behaviour was not guaranteed and did not feature in the tests.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:future Future]
|
||||
|
||||
The following features will be included in next releases.
|
||||
|
||||
# Add some minor features, in particular
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7589 #7589] Synchro: Add polymorphic lockables.
|
||||
|
||||
# Add some features based on C++ proposals, in particular
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8273 #8273] Synchro: Add externally locked streams.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8514 #8514] Async: Add a thread_pool executor with work stealing.
|
||||
|
||||
# And some additional extensions related to futures as:
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8517 #8517] Async: Add a variadic shared_future::then.
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
247
doc/compliance.qbk
Normal file
247
doc/compliance.qbk
Normal file
@@ -0,0 +1,247 @@
|
||||
[/
|
||||
(C) Copyright 2011-2013 Vicente J. Botet Escriba.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:compliance Conformance and Extension]
|
||||
|
||||
[section:cpp11 C++11 standard Thread library]
|
||||
|
||||
[note [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3376.html C++11 - Standard for Programming Language C++]]]
|
||||
|
||||
|
||||
[table C++11 standard Conformance
|
||||
[[Section] [Description] [Status] [Comments] [Ticket]]
|
||||
[[30] [Thread support library] [Yes] [-] [-]]
|
||||
[[30.1] [General] [-] [-] [-]]
|
||||
[[30.2] [Requirements] [-] [-] [-]]
|
||||
[[30.2.1] [Template parameter names] [-] [-] [-]]
|
||||
[[30.2.2] [Exceptions] [Yes] [-] [-]]
|
||||
[[30.2.3] [Native handles] [Yes] [-] [-]]
|
||||
[[30.2.4] [Timing specifications] [Yes] [-] [-]]
|
||||
[[30.2.5] [Requirements for Lockable types] [Yes] [-] [-]]
|
||||
[[30.2.5.1] [In general] [-] [-] [-]]
|
||||
[[30.2.5.2] [BasicLockable requirements] [Yes] [-] [-]]
|
||||
[[30.2.5.3] [Lockable requirements] [yes] [-] [-]]
|
||||
[[30.2.5.4] [TimedLockable requirements] [Yes] [-] [-]]
|
||||
[[30.2.6] [decay_copy] [-] [-] [-]]
|
||||
[[30.3] [Threads] [Yes] [-] [-]]
|
||||
[[30.3.1] [Class thread] [Yes] [-] [-]]
|
||||
[[30.3.1.1] [Class thread::id] [Yes] [-] [-]]
|
||||
[[30.3.1.2] [thread constructors] [Partial] [-] [-]]
|
||||
[[30.3.1.3] [thread destructor] [Yes] [-] [-]]
|
||||
[[30.3.1.4] [thread assignment] [Yes] [-] [-]]
|
||||
[[30.3.1.5] [thread members] [Yes] [-] [-]]
|
||||
[[30.3.1.6] [thread static members] [Yes] [-] [-]]
|
||||
[[30.3.1.7] [thread specialized algorithms] [Yes] [-] [-]]
|
||||
|
||||
[[30.3.2] [Namespace this_thread] [Yes] [-] [-]]
|
||||
[[30.4] [Mutual exclusion] [Partial] [-] [-]]
|
||||
[[30.4.1] [Mutex requirements] [Yes] [-] [-]]
|
||||
[[30.4.1.1] [In general] [Yes] [-] [-]]
|
||||
[[30.4.1.2] [Mutex types] [Yes] [-] [-]]
|
||||
[[30.4.1.2.1] [Class mutex] [Yes] [-] [-]]
|
||||
[[30.4.1.2.2] [Class recursive_mutex] [Yes] [-] [-]]
|
||||
[[30.4.1.3] [Timed mutex types] [Yes] [-] [-]]
|
||||
[[30.4.1.3.1] [Class timed_mutex] [Yes] [-] [-]]
|
||||
[[30.4.1.3.1] [Class recursive_timed_mutex] [Yes] [-] [-]]
|
||||
[[30.4.2] [Locks] [Yes] [-] [-]]
|
||||
[[30.4.2.1] [Class template lock_guard] [Yes] [-] [-]]
|
||||
[[30.4.2.2] [Class template unique_lock] [Yes] [-] [-]]
|
||||
[[30.4.2.2.1] [unique_lock constructors, destructor, and assignment] [Yes] [-] [-]]
|
||||
[[30.4.2.2.2] [unique_lock locking] [Yes] [-] [-]]
|
||||
[[30.4.2.2.3] [unique_lock modifiers] [Yes] [-] [-]]
|
||||
[[30.4.2.2.4] [unique_lock observers] [Yes] [ - ] [-]]
|
||||
[[30.4.3] [Generic locking algorithms] [Partial] [variadic] [#6227]]
|
||||
[[30.4.4] [Call once] [Yes] [-] [-]]
|
||||
[[30.4.4.1] [Struct once_flag] [Yes] [-] [-]]
|
||||
[[30.4.4.2] [Function call_once] [Yes] [-] [-]]
|
||||
[[30.5] [Condition variables] [Yes] [-] [-]]
|
||||
[[30.5.1] [Class condition_variable] [Yes] [-] [-]]
|
||||
[[30.5.2] [Class condition_variable_any] [Yes] [-] [-]]
|
||||
[[30.6] [Futures] [Yes] [-] [-]]
|
||||
[[30.6.1] [Overview] [Partial] [-] [-]]
|
||||
[[30.6.2] [Error handling] [Yes] [-] [-]]
|
||||
[[30.6.3] [Class future_error] [-] [-] [-]]
|
||||
[[30.6.4] [Shared state] [-] [-] [-]]
|
||||
[[30.6.5] [Class template promise] [Yes] [-] [-]]
|
||||
[[30.6.6] [Class template future] [Yes] [-] [-]]
|
||||
[[30.6.7] [Class template shared_future] [Yes] [-] [-]]
|
||||
[[30.6.8] [Function template async] [Yes] [-] [-]]
|
||||
[[30.6.9] [Class template packaged_task] [Yes] [-] [-]]
|
||||
]
|
||||
|
||||
|
||||
[table Extension
|
||||
[[Section] [Description] [Comments]]
|
||||
[[30.3.1.5.x] [interrupt] [-]]
|
||||
[[30.3.2.x] [Interruption] [-]]
|
||||
[[30.3.2.y] [at_thread_exit] [-]]
|
||||
[[30.4.3.x] [Generic locking algorithms begin/end] [-]]
|
||||
]
|
||||
|
||||
[/
|
||||
[[30.x] [Thread Local Storage] [-]]
|
||||
[[30.y] [Class thread_group] [-]]
|
||||
]
|
||||
[endsect]
|
||||
[section:cxx14 C++14 standard Thread library - accepted changes]
|
||||
|
||||
[note [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.html Working Draft, Standard for Programming Language C++]]
|
||||
|
||||
|
||||
[table [@http://isocpp.org/files/papers/N3659.html N3659 Shared locking in C++ revision 2] Conformance
|
||||
[[Section] [Description] [Status] [Comments]]
|
||||
[[30.4.1.4] [Shared Lockables Types] [Yes] [ - ]]
|
||||
[[30.4.1.4.1] [shared_mutex class] [Yes] [ - ]]
|
||||
[[30.4.2.3] [Class template shared_lock] [Yes] [-]]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:cxx1y C++14 TS Extensions for Concurrency V1 ]
|
||||
|
||||
[note [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4107.html N4107-Extensions for Concurrency]]
|
||||
|
||||
|
||||
[table Improvements to std::future<T> and related APIs]
|
||||
[[Section] [Description] [Status] [Comments]]
|
||||
[[2.1] [ - ] [ - ] [ - ]]
|
||||
[[2.2] [Class template future] [Partial] [ - ]]
|
||||
[[2.2] [then] [ Partial ] [ without implicit unwrapping #10550 and blocking #10551 ]]
|
||||
[[2.2] [is_ready] [ Yes ] [ - ]]
|
||||
[[2.3] [Class template shared_future] [Partial] [ - ]]
|
||||
[[2.3] [then] [ Partial ] [ Without implicit unwrapping #10550 and blocking #10551 ]]
|
||||
[[2.3] [is_ready] [ Yes ] [ - ]]
|
||||
[[2.4] [Function template when_all] [Partial] [ interface not complete #10426 and blocking #10551 ]]
|
||||
[[2.5] [Function template when_any] [Partial] [ interface not complete #10427 and blocking #10551 ]]
|
||||
[[2.6] [Function template when_any_back] [No] [ #XXXX ]]
|
||||
[[2.7] [Function template make_ready_future] [Yes] [ - ]]
|
||||
]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:cxx1y C++1z TS Concurrency - On going proposals]
|
||||
|
||||
[section:latch C++ Latches and Barriers]
|
||||
|
||||
[note [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3600.html N3600 C++ Latches and Barriers]]
|
||||
[note [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3817.html N3817 C++ Latches and Barriers]]
|
||||
|
||||
[table C++ Latches and Barriers Conformance
|
||||
[[Section] [Description] [Status] [Comments]]
|
||||
[[X.1] [Class latch] [Partial] [ A new class latch has been added. The interface is a super set of the one of the proposal, taking some of the functions of the class barrier.]]
|
||||
[[X.2] [Class barrier] [No] [ Even if Boost.Thread has a class boost:barrier it doesn't provides the same kind of services. There is an experimental completion_latch that could be used instead. ]]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:queue C++ Concurrent Queues]
|
||||
|
||||
[note [@ http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3533.html N3533 C++ Concurrent Queues]]
|
||||
|
||||
[table C++ Concurrent Queues Conformance
|
||||
[[Section] [Description] [Status] [Comments]]
|
||||
[[X.1] [Conceptual interface] [Partial] [ The interface provided has some differences respect to this proposal. All the functions having a queue_op_status are not provided. No lock-free concrete classes ]]
|
||||
[[X.1.1] [Basic Operations] [Partial] [ - ]]
|
||||
[[X.1.1.1] [push] [yes] [ renamed push_back. ]]
|
||||
[[X.1.1.2] [value_pop] [no] [ renamed pull_front with two flavors. ]]
|
||||
[[X.1.2] [Non-waiting operations] [ - ] [ - ]]
|
||||
[[X.1.2.1] [try_push] [yes] [ renamed try_push_back ]]
|
||||
[[X.1.2.2] [try_pop] [yes] [ renamed try_pull_back ]]
|
||||
[[X.1.3] [Non-blocking operations] [ - ] [ - ]]
|
||||
[[X.1.3.1] [nonblocking_push] [Yes] [ renamed nonblocking_push_back ]]
|
||||
[[X.1.3.2] [nonblocking_pop] [Yes] [ renamed nonblocking_pull_front ]]
|
||||
[[X.1.4] [Push-front operations] [No] [ - ]]
|
||||
[[X.1.5] [Closed queues] [Partial] [ - ]]
|
||||
[[X.1.5.1] [close] [Yes] [ - ]]
|
||||
[[X.1.5.2] [is_closed] [Yes] [ renamed closed ]]
|
||||
[[X.1.5.3] [wait_push] [Yes] [ renamed wait_push_back ]]
|
||||
[[X.1.5.4] [wait_pop] [Yes] [ renamed wait_pull_front ]]
|
||||
[[X.1.5.5] [wait_push_front] [no] [ - ]]
|
||||
[[X.1.5.6] [wait_pop_back] [no] [ - ]]
|
||||
[[X.1.5.6] [open] [no] [ - ]]
|
||||
[[X.1.6] [Empty and Full Queues] [Yes] [ - ]]
|
||||
[[X.1.6.1] [is_empty] [Yes] [ - ]]
|
||||
[[X.1.6.2] [is_full] [Yes] [ Added capacity ]]
|
||||
[[X.1.7] [Queue Names] [No] [ Not considered a must for the time been. ]]
|
||||
[[X.1.8] [Element Type Requirements] [Yes?] [ - ]]
|
||||
[[X.1.9] [Exception Handling] [Yes?] [ - ]]
|
||||
[[X.1.10] [Queue Ordering] [Yes?] [ - ]]
|
||||
[[X.1.11] [Lock-Free Implementations] [No] [ waiting to stabilize the lock-based interface. Will use Boost.LockFree once it is Boost.Move aware. ]]
|
||||
[[X.2] [Concrete queues] [Partial] [ - ]]
|
||||
[[X.2.1] [Locking Buffer Queue] [Partial] [ classes sync_queue and a sync_bounded_queue. ]]
|
||||
[[X.2.1] [Lock-Free Buffer Queue] [No] [ waiting to stabilize the lock-based interface. Will use Boost.LockFree once it is Boost.Move aware. ]]
|
||||
[[X.3] [Additional Conceptual Tools] [No] [ - ]]
|
||||
[[X.3.1] [Fronts and Backs] [No] [ - ]]
|
||||
[[X.3.2] [Streaming Iterators] [No] [ - ]]
|
||||
[[X.3.3] [Storage Iterators] [No] [ - ]]
|
||||
[[X.3.4] [Binary Interfaces] [No] [ - ]]
|
||||
[[X.3.4] [Managed Indirection] [No] [ - ]]
|
||||
]
|
||||
[endsect]
|
||||
[section:executors Asynchronous Executors]
|
||||
|
||||
[note [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3785.pdf N3785 Executors and Schedulers]]
|
||||
|
||||
[table Asynchronous Executors
|
||||
[[Section] [Description] [Status] [Comments]]
|
||||
[[V.1.1] [Class executor] [Yes] [ - ]]
|
||||
[[V.1.1] [add] [Yes] [ renamed with a function template submit ]]
|
||||
[[V.1.1] [num_of_pendin_closures] [No] [ ]]
|
||||
[[V.1.2] [Class sceduled_executor] [No] [ - ]]
|
||||
[[V.1.2] [add_at] [No] [ renamed with a function template submit_at ]]
|
||||
[[V.1.2] [add_after] [No] [ renamed with a function template submit_after ]]
|
||||
[[V.2] [Concrete executor classes] [No] [ - ]]
|
||||
[[V.2.1] [thread_pool] [Yes] [ static version Basic_thread_pool, dynamic one execduler_adaptor<basic_thread_pool> ]]
|
||||
[[V.2.2] [serial_executor] [yes] [ - ]]
|
||||
[[V.2.3] [loop_executor] [Yes] [ static version loop_scheduler, dynamic one execduler_adaptor<loop_scheduler> ]]
|
||||
[[V.2.4] [inline_executor] [Yes] [ static version inline_executor, dynamic one execduler_adaptor<inline_executor> ]]
|
||||
[[V.2.5] [thread_executor] [Yes] [ static version thread_executor, dynamic one execduler_adaptor<thread_executor> ]]
|
||||
]
|
||||
|
||||
[note [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3784.pdf N3784-Improvements to `std::future<T> and Related APIs]]
|
||||
|
||||
[table `async, future/shared_future::then`and Executors
|
||||
[[Section] [Description] [Status] [Comments]]
|
||||
[[30.6.6] [`future<T>::then`] [Yes] [ ]]
|
||||
[[30.6.7] [`shared_future<T>::then`] [Yes] [ ]]
|
||||
[[30.6.8] [`async`] [Yes] [ - ]]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:stream_mutex C++ Stream Mutexes - C++ Stream Guards]
|
||||
|
||||
While Boost.Thread implementation of stream mutexes differ in the approach, it is worth comparing with the current trend on the standard.
|
||||
|
||||
[note These functions are based on [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3535.html [*N3535 - C++ Stream Mutexes]] by Lawrence Crowl.]
|
||||
|
||||
[note This proposal has been replaced already by [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3678.html N3678 - C++ Stream Guards], which has been replaced by [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3678.html N3665 - Uninterleaved String Output Streaming] and [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3678.html N3750 - C++ Ostream Buffers]]
|
||||
|
||||
[table C++ Stream Mutexes Conformance
|
||||
[[Section] [Description] [Status] [Comments]]
|
||||
[[X.1] [Class template stream_mutex] [Partial] [ Renamed externally_locked_stream<> ]]
|
||||
[[X.2.1] [constructor] [Partial] [ externally_locked_stream needs a mutex in addition as argument. ]]
|
||||
[[X.2.2] [lock] [yes] [ - ]]
|
||||
[[X.2.3] [unlock] [yes] [ - ]]
|
||||
[[X.2.4] [try_lock] [yes] [ - ]]
|
||||
[[X.2.5] [hold] [Yes] [ - ]]
|
||||
[[X.2.6] [bypass] [Yes] [ - ]]
|
||||
[[X.2] [Class template stream_guard] [Yes] [ - ]]
|
||||
[[X.2.1] [stream_guard] [Yes] [ - ]]
|
||||
[[X.2.2] [~stream_guard] [Yes] [ - ]]
|
||||
[[X.2.3] [bypass] [Yes] [ - ]]
|
||||
[[X.3] [Stream Operators] [Yes] [-]]
|
||||
[[X.4] [Predefined Objects] [No] [-]]
|
||||
]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
2305
doc/concepts.xml
2305
doc/concepts.xml
File diff suppressed because it is too large
Load Diff
@@ -1,196 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/condition.hpp"
|
||||
last-revision="$Date$">
|
||||
<namespace name="boost">
|
||||
<class name="condition">
|
||||
<inherit access="private">
|
||||
<type><classname>boost::noncopyable</classname></type>
|
||||
<purpose>Exposition only</purpose>
|
||||
</inherit>
|
||||
|
||||
<purpose>
|
||||
<para>An object of class <classname>condition</classname> is a
|
||||
synchronization primitive used to cause a thread to wait until a
|
||||
particular shared-data condition (or time) is met.</para>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<para>A <classname>condition</classname> object is always used in
|
||||
conjunction with a <link linkend="thread.concepts.mutexes">mutex</link>
|
||||
object (an object whose type is a model of a <link
|
||||
linkend="thread.concepts.Mutex">Mutex</link> or one of its
|
||||
refinements). The mutex object must be locked prior to waiting on the
|
||||
condition, which is verified by passing a lock object (an object whose
|
||||
type is a model of <link linkend="thread.concepts.Lock">Lock</link> or
|
||||
one of its refinements) to the <classname>condition</classname> object's
|
||||
wait functions. Upon blocking on the <classname>condition</classname>
|
||||
object, the thread unlocks the mutex object. When the thread returns
|
||||
from a call to one of the <classname>condition</classname> object's wait
|
||||
functions the mutex object is again locked. The tricky unlock/lock
|
||||
sequence is performed automatically by the
|
||||
<classname>condition</classname> object's wait functions.</para>
|
||||
<para>The <classname>condition</classname> type is often used to
|
||||
implement the Monitor Object and other important patterns (see
|
||||
&cite.SchmidtStalRohnertBuschmann; and &cite.Hoare74;). Monitors are one
|
||||
of the most important patterns for creating reliable multithreaded
|
||||
programs.</para>
|
||||
<para>See <xref linkend="thread.glossary"/> for definitions of <link
|
||||
linkend="thread.glossary.thread-state">thread states</link>
|
||||
blocked and ready. Note that "waiting" is a synonym for blocked.</para>
|
||||
</description>
|
||||
|
||||
<constructor>
|
||||
<effects><simpara>Constructs a <classname>condition</classname>
|
||||
object.</simpara></effects>
|
||||
</constructor>
|
||||
|
||||
<destructor>
|
||||
<effects><simpara>Destroys <code>*this</code>.</simpara></effects>
|
||||
</destructor>
|
||||
|
||||
<method-group name="notification">
|
||||
<method name="notify_one">
|
||||
<type>void</type>
|
||||
<effects><simpara>If there is a thread waiting on <code>*this</code>,
|
||||
change that thread's state to ready. Otherwise there is no
|
||||
effect.</simpara></effects>
|
||||
<notes><simpara>If more than one thread is waiting on <code>*this</code>,
|
||||
it is unspecified which is made ready. After returning to a ready
|
||||
state the notified thread must still acquire the mutex again (which
|
||||
occurs within the call to one of the <classname>condition</classname>
|
||||
object's wait functions.)</simpara></notes>
|
||||
</method>
|
||||
|
||||
<method name="notify_all">
|
||||
<type>void</type>
|
||||
<effects><simpara>Change the state of all threads waiting on
|
||||
<code>*this</code> to ready. If there are no waiting threads,
|
||||
<code>notify_all()</code> has no effect.</simpara></effects>
|
||||
</method>
|
||||
</method-group>
|
||||
|
||||
<method-group name="waiting">
|
||||
<method name="wait">
|
||||
<template>
|
||||
<template-type-parameter name="ScopedLock"/>
|
||||
</template>
|
||||
|
||||
<type>void</type>
|
||||
|
||||
<parameter name="lock">
|
||||
<paramtype>ScopedLock&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<requires><simpara><code>ScopedLock</code> meets the <link
|
||||
linkend="thread.concepts.ScopedLock">ScopedLock</link>
|
||||
requirements.</simpara></requires>
|
||||
<effects><simpara>Releases the lock on the <link
|
||||
linkend="thread.concepts.mutexes">mutex object</link>
|
||||
associated with <code>lock</code>, blocks the current thread of execution
|
||||
until readied by a call to <code>this->notify_one()</code>
|
||||
or<code> this->notify_all()</code>, and then reacquires the
|
||||
lock.</simpara></effects>
|
||||
<throws><simpara><classname>lock_error</classname> if
|
||||
<code>!lock.locked()</code></simpara></throws>
|
||||
</method>
|
||||
|
||||
<method name="wait">
|
||||
<template>
|
||||
<template-type-parameter name="ScopedLock"/>
|
||||
<template-type-parameter name="Pred"/>
|
||||
</template>
|
||||
|
||||
<type>void</type>
|
||||
|
||||
<parameter name="lock">
|
||||
<paramtype>ScopedLock&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<parameter name="pred">
|
||||
<paramtype>Pred</paramtype>
|
||||
</parameter>
|
||||
|
||||
<requires><simpara><code>ScopedLock</code> meets the <link
|
||||
linkend="thread.concepts.ScopedLock">ScopedLock</link>
|
||||
requirements and the return from <code>pred()</code> is
|
||||
convertible to <code>bool</code>.</simpara></requires>
|
||||
<effects><simpara>As if: <code>while (!pred())
|
||||
wait(lock)</code></simpara></effects>
|
||||
<throws><simpara><classname>lock_error</classname> if
|
||||
<code>!lock.locked()</code></simpara></throws>
|
||||
</method>
|
||||
|
||||
<method name="timed_wait">
|
||||
<template>
|
||||
<template-type-parameter name="ScopedLock"/>
|
||||
</template>
|
||||
|
||||
<type>bool</type>
|
||||
|
||||
<parameter name="lock">
|
||||
<paramtype>ScopedLock&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<parameter name="xt">
|
||||
<paramtype>const <classname>boost::xtime</classname>&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<requires><simpara><code>ScopedLock</code> meets the <link
|
||||
linkend="thread.concepts.ScopedLock">ScopedLock</link>
|
||||
requirements.</simpara></requires>
|
||||
<effects><simpara>Releases the lock on the <link
|
||||
linkend="thread.concepts.mutexes">mutex object</link>
|
||||
associated with <code>lock</code>, blocks the current thread of execution
|
||||
until readied by a call to <code>this->notify_one()</code>
|
||||
or<code> this->notify_all()</code>, or until time <code>xt</code>
|
||||
is reached, and then reacquires the lock.</simpara></effects>
|
||||
<returns><simpara><code>false</code> if time <code>xt</code> is reached,
|
||||
otherwise <code>true</code>.</simpara></returns>
|
||||
<throws><simpara><classname>lock_error</classname> if
|
||||
<code>!lock.locked()</code></simpara></throws>
|
||||
</method>
|
||||
|
||||
<method name="timed_wait">
|
||||
<template>
|
||||
<template-type-parameter name="ScopedLock"/>
|
||||
<template-type-parameter name="Pred"/>
|
||||
</template>
|
||||
|
||||
<type>bool</type>
|
||||
|
||||
<parameter name="lock">
|
||||
<paramtype>ScopedLock&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<parameter name="xt">
|
||||
<paramtype>const <classname>boost::xtime</classname>&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<parameter name="pred">
|
||||
<paramtype>Pred</paramtype>
|
||||
</parameter>
|
||||
|
||||
<requires><simpara><code>ScopedLock</code> meets the <link
|
||||
linkend="thread.concepts.ScopedLock">ScopedLock</link>
|
||||
requirements and the return from <code>pred()</code> is
|
||||
convertible to <code>bool</code>.</simpara></requires>
|
||||
<effects><simpara>As if: <code>while (!pred()) { if (!timed_wait(lock,
|
||||
xt)) return false; } return true;</code></simpara></effects>
|
||||
<returns><simpara><code>false</code> if <code>xt</code> is reached,
|
||||
otherwise <code>true</code>.</simpara></returns>
|
||||
<throws><simpara><classname>lock_error</classname> if
|
||||
<code>!lock.locked()</code></simpara></throws>
|
||||
</method>
|
||||
</method-group>
|
||||
</class>
|
||||
</namespace>
|
||||
</header>
|
||||
790
doc/condition_variables.qbk
Normal file
790
doc/condition_variables.qbk
Normal file
@@ -0,0 +1,790 @@
|
||||
[/
|
||||
(C) Copyright 2007-11 Anthony Williams.
|
||||
(C) Copyright 2011-12 Vicente J. Botet Escriba.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:condvar_ref Condition Variables]
|
||||
|
||||
[heading Synopsis]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
enum class cv_status;
|
||||
{
|
||||
no_timeout,
|
||||
timeout
|
||||
};
|
||||
class condition_variable;
|
||||
class condition_variable_any;
|
||||
void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
|
||||
}
|
||||
|
||||
The classes `condition_variable` and `condition_variable_any` provide a
|
||||
mechanism for one thread to wait for notification from another thread that a
|
||||
particular condition has become true. The general usage pattern is that one
|
||||
thread locks a mutex and then calls `wait` on an instance of
|
||||
`condition_variable` or `condition_variable_any`. When the thread is woken from
|
||||
the wait, then it checks to see if the appropriate condition is now true, and
|
||||
continues if so. If the condition is not true, then the thread then calls `wait`
|
||||
again to resume waiting. In the simplest case, this condition is just a boolean
|
||||
variable:
|
||||
|
||||
boost::condition_variable cond;
|
||||
boost::mutex mut;
|
||||
bool data_ready;
|
||||
|
||||
void process_data();
|
||||
|
||||
void wait_for_data_to_process()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lock(mut);
|
||||
while(!data_ready)
|
||||
{
|
||||
cond.wait(lock);
|
||||
}
|
||||
process_data();
|
||||
}
|
||||
|
||||
Notice that the `lock` is passed to `wait`: `wait` will atomically add the
|
||||
thread to the set of threads waiting on the condition variable, and unlock the
|
||||
mutex. When the thread is woken, the mutex will be locked again before the call
|
||||
to `wait` returns. This allows other threads to acquire the mutex in order to
|
||||
update the shared data, and ensures that the data associated with the condition
|
||||
is correctly synchronized.
|
||||
|
||||
In the mean time, another thread sets the condition to `true`, and then calls
|
||||
either `notify_one` or `notify_all` on the condition variable to wake one
|
||||
waiting thread or all the waiting threads respectively.
|
||||
|
||||
void retrieve_data();
|
||||
void prepare_data();
|
||||
|
||||
void prepare_data_for_processing()
|
||||
{
|
||||
retrieve_data();
|
||||
prepare_data();
|
||||
{
|
||||
boost::lock_guard<boost::mutex> lock(mut);
|
||||
data_ready=true;
|
||||
}
|
||||
cond.notify_one();
|
||||
}
|
||||
|
||||
Note that the same mutex is locked before the shared data is updated, but that
|
||||
the mutex does not have to be locked across the call to `notify_one`.
|
||||
|
||||
This example uses an object of type `condition_variable`, but would work just as
|
||||
well with an object of type `condition_variable_any`: `condition_variable_any`
|
||||
is more general, and will work with any kind of lock or mutex, whereas
|
||||
`condition_variable` requires that the lock passed to `wait` is an instance of
|
||||
`boost::unique_lock<boost::mutex>`. This enables `condition_variable` to make
|
||||
optimizations in some cases, based on the knowledge of the mutex type;
|
||||
`condition_variable_any` typically has a more complex implementation than
|
||||
`condition_variable`.
|
||||
|
||||
[section:condition_variable Class `condition_variable`]
|
||||
|
||||
//#include <boost/thread/condition_variable.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class condition_variable
|
||||
{
|
||||
public:
|
||||
condition_variable();
|
||||
~condition_variable();
|
||||
|
||||
void notify_one() noexcept;
|
||||
void notify_all() noexcept;
|
||||
|
||||
void wait(boost::unique_lock<boost::mutex>& lock);
|
||||
|
||||
template<typename predicate_type>
|
||||
void wait(boost::unique_lock<boost::mutex>& lock,predicate_type predicate);
|
||||
|
||||
template <class Clock, class Duration>
|
||||
typename cv_status::type
|
||||
wait_until(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::time_point<Clock, Duration>& t);
|
||||
|
||||
template <class Clock, class Duration, class Predicate>
|
||||
bool
|
||||
wait_until(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::time_point<Clock, Duration>& t,
|
||||
Predicate pred);
|
||||
|
||||
template <class Rep, class Period>
|
||||
typename cv_status::type
|
||||
wait_for(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::duration<Rep, Period>& d);
|
||||
|
||||
template <class Rep, class Period, class Predicate>
|
||||
bool
|
||||
wait_for(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::duration<Rep, Period>& d,
|
||||
Predicate pred);
|
||||
|
||||
#if defined BOOST_THREAD_USES_DATETIME
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::system_time const& abs_time);
|
||||
template<typename duration_type>
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,duration_type const& rel_time);
|
||||
template<typename predicate_type>
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::system_time const& abs_time,predicate_type predicate);
|
||||
template<typename duration_type,typename predicate_type>
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,duration_type const& rel_time,predicate_type predicate);
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::xtime const& abs_time);
|
||||
|
||||
template<typename predicate_type>
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::xtime const& abs_time,predicate_type predicate);
|
||||
#endif
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
[section:constructor `condition_variable()`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Constructs an object of class `condition_variable`.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error occurs.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:destructor `~condition_variable()`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Precondition:] [All threads waiting on `*this` have been notified by a call to
|
||||
`notify_one` or `notify_all` (though the respective calls to `wait` or
|
||||
`timed_wait` need not have returned).]]
|
||||
|
||||
[[Effects:] [Destroys the object.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:notify_one `void notify_one()`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If any threads are currently __blocked__ waiting on `*this` in a call
|
||||
to `wait` or `timed_wait`, unblocks one of those threads.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:notify_all `void notify_all()`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If any threads are currently __blocked__ waiting on `*this` in a call
|
||||
to `wait` or `timed_wait`, unblocks all of those threads.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait `void wait(boost::unique_lock<boost::mutex>& lock)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Precondition:] [`lock` is locked by the current thread, and either no other
|
||||
thread is currently waiting on `*this`, or the execution of the `mutex()` member
|
||||
function on the `lock` objects supplied in the calls to `wait` or `timed_wait`
|
||||
in all the threads currently waiting on `*this` would return the same value as
|
||||
`lock->mutex()` for this call to `wait`.]]
|
||||
|
||||
[[Effects:] [Atomically call `lock.unlock()` and blocks the current thread. The
|
||||
thread will unblock when notified by a call to `this->notify_one()` or
|
||||
`this->notify_all()`, or spuriously. When the thread is unblocked (for whatever
|
||||
reason), the lock is reacquired by invoking `lock.lock()` before the call to
|
||||
`wait` returns. The lock is also reacquired by invoking `lock.lock()` if the
|
||||
function exits with an exception.]]
|
||||
|
||||
[[Postcondition:] [`lock` is locked by the current thread.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error
|
||||
occurs. __thread_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __thread__ object associated with the current thread of execution.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_predicate `template<typename predicate_type> void wait(boost::unique_lock<boost::mutex>& lock, predicate_type pred)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [As-if ``
|
||||
while(!pred())
|
||||
{
|
||||
wait(lock);
|
||||
}
|
||||
``]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_wait `bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::system_time const& abs_time)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Precondition:] [`lock` is locked by the current thread, and either no other
|
||||
thread is currently waiting on `*this`, or the execution of the `mutex()` member
|
||||
function on the `lock` objects supplied in the calls to `wait` or `timed_wait`
|
||||
in all the threads currently waiting on `*this` would return the same value as
|
||||
`lock->mutex()` for this call to `wait`.]]
|
||||
|
||||
[[Effects:] [Atomically call `lock.unlock()` and blocks the current thread. The
|
||||
thread will unblock when notified by a call to `this->notify_one()` or
|
||||
`this->notify_all()`, when the time as reported by `boost::get_system_time()`
|
||||
would be equal to or later than the specified `abs_time`, or spuriously. When
|
||||
the thread is unblocked (for whatever reason), the lock is reacquired by
|
||||
invoking `lock.lock()` before the call to `wait` returns. The lock is also
|
||||
reacquired by invoking `lock.lock()` if the function exits with an exception.]]
|
||||
|
||||
[[Returns:] [`false` if the call is returning because the time specified by
|
||||
`abs_time` was reached, `true` otherwise.]]
|
||||
|
||||
[[Postcondition:] [`lock` is locked by the current thread.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error
|
||||
occurs. __thread_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __thread__ object associated with the current thread of execution.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_wait_rel `template<typename duration_type> bool timed_wait(boost::unique_lock<boost::mutex>& lock,duration_type const& rel_time)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Precondition:] [`lock` is locked by the current thread, and either no other
|
||||
thread is currently waiting on `*this`, or the execution of the `mutex()` member
|
||||
function on the `lock` objects supplied in the calls to `wait` or `timed_wait`
|
||||
in all the threads currently waiting on `*this` would return the same value as
|
||||
`lock->mutex()` for this call to `wait`.]]
|
||||
|
||||
[[Effects:] [Atomically call `lock.unlock()` and blocks the current thread. The
|
||||
thread will unblock when notified by a call to `this->notify_one()` or
|
||||
`this->notify_all()`, after the period of time indicated by the `rel_time`
|
||||
argument has elapsed, or spuriously. When the thread is unblocked (for whatever
|
||||
reason), the lock is reacquired by invoking `lock.lock()` before the call to
|
||||
`wait` returns. The lock is also reacquired by invoking `lock.lock()` if the
|
||||
function exits with an exception.]]
|
||||
|
||||
[[Returns:] [`false` if the call is returning because the time period specified
|
||||
by `rel_time` has elapsed, `true` otherwise.]]
|
||||
|
||||
[[Postcondition:] [`lock` is locked by the current thread.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error
|
||||
occurs. __thread_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __thread__ object associated with the current thread of execution.]]
|
||||
|
||||
]
|
||||
|
||||
[note The duration overload of timed_wait is difficult to use correctly. The overload taking a predicate should be preferred in most cases.]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_wait_predicate `template<typename predicate_type> bool timed_wait(boost::unique_lock<boost::mutex>& lock, boost::system_time const& abs_time, predicate_type pred)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [As-if ``
|
||||
while(!pred())
|
||||
{
|
||||
if(!timed_wait(lock,abs_time))
|
||||
{
|
||||
return pred();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
``]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:wait_until `template <class Clock, class Duration> cv_status wait_until(boost::unique_lock<boost::mutex>& lock, const chrono::time_point<Clock, Duration>& abs_time)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Precondition:] [`lock` is locked by the current thread, and either no other
|
||||
thread is currently waiting on `*this`, or the execution of the `mutex()` member
|
||||
function on the `lock` objects supplied in the calls to `wait` or `wait_for` or `wait_until`
|
||||
in all the threads currently waiting on `*this` would return the same value as
|
||||
`lock->mutex()` for this call to `wait`.]]
|
||||
|
||||
[[Effects:] [Atomically call `lock.unlock()` and blocks the current thread. The
|
||||
thread will unblock when notified by a call to `this->notify_one()` or
|
||||
`this->notify_all()`, when the time as reported by `Clock::now()`
|
||||
would be equal to or later than the specified `abs_time`, or spuriously. When
|
||||
the thread is unblocked (for whatever reason), the lock is reacquired by
|
||||
invoking `lock.lock()` before the call to `wait` returns. The lock is also
|
||||
reacquired by invoking `lock.lock()` if the function exits with an exception.]]
|
||||
|
||||
[[Returns:] [`cv_status::timeout` if the call is returning because the time specified by
|
||||
`abs_time` was reached, `cv_status::no_timeout` otherwise.]]
|
||||
|
||||
[[Postcondition:] [`lock` is locked by the current thread.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error
|
||||
occurs. __thread_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __thread__ object associated with the current thread of execution.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_for `template <class Rep, class Period> cv_status wait_for(boost::unique_lock<boost::mutex>& lock, const chrono::duration<Rep, Period>& rel_time)`]
|
||||
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Precondition:] [`lock` is locked by the current thread, and either no other
|
||||
thread is currently waiting on `*this`, or the execution of the `mutex()` member
|
||||
function on the `lock` objects supplied in the calls to `wait` or `wait_until` or `wait_for`
|
||||
in all the threads currently waiting on `*this` would return the same value as
|
||||
`lock->mutex()` for this call to `wait`.]]
|
||||
|
||||
[[Effects:] [Atomically call `lock.unlock()` and blocks the current thread. The
|
||||
thread will unblock when notified by a call to `this->notify_one()` or
|
||||
`this->notify_all()`, after the period of time indicated by the `rel_time`
|
||||
argument has elapsed, or spuriously. When the thread is unblocked (for whatever
|
||||
reason), the lock is reacquired by invoking `lock.lock()` before the call to
|
||||
`wait` returns. The lock is also reacquired by invoking `lock.lock()` if the
|
||||
function exits with an exception.]]
|
||||
|
||||
[[Returns:] [`cv_status::timeout ` if the call is returning because the time period specified
|
||||
by `rel_time` has elapsed, `cv_status::no_timeout ` otherwise.]]
|
||||
|
||||
[[Postcondition:] [`lock` is locked by the current thread.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error
|
||||
occurs. __thread_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __thread__ object associated with the current thread of execution.]]
|
||||
|
||||
]
|
||||
|
||||
[note The duration overload of timed_wait is difficult to use correctly. The overload taking a predicate should be preferred in most cases.]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_until_predicate `template <class Clock, class Duration, class Predicate> bool wait_until(boost::unique_lock<boost::mutex>& lock, const chrono::time_point<Clock, Duration>& abs_time, Predicate pred)`]
|
||||
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [As-if ``
|
||||
while(!pred())
|
||||
{
|
||||
if(!wait_until(lock,abs_time))
|
||||
{
|
||||
return pred();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
``]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_for_predicate `template <class Rep, class Period, class Predicate> bool wait_for(boost::unique_lock<boost::mutex>& lock, const chrono::duration<Rep, Period>& rel_time, Predicate pred)`]
|
||||
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [As-if ``
|
||||
return wait_until(lock, chrono::steady_clock::now() + d, boost::move(pred));
|
||||
``]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:condition_variable_any Class `condition_variable_any`]
|
||||
|
||||
//#include <boost/thread/condition_variable.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class condition_variable_any
|
||||
{
|
||||
public:
|
||||
condition_variable_any();
|
||||
~condition_variable_any();
|
||||
|
||||
void notify_one();
|
||||
void notify_all();
|
||||
|
||||
template<typename lock_type>
|
||||
void wait(lock_type& lock);
|
||||
|
||||
template<typename lock_type,typename predicate_type>
|
||||
void wait(lock_type& lock,predicate_type predicate);
|
||||
|
||||
template <class lock_type, class Clock, class Duration>
|
||||
cv_status wait_until(
|
||||
lock_type& lock,
|
||||
const chrono::time_point<Clock, Duration>& t);
|
||||
|
||||
template <class lock_type, class Clock, class Duration, class Predicate>
|
||||
bool wait_until(
|
||||
lock_type& lock,
|
||||
const chrono::time_point<Clock, Duration>& t,
|
||||
Predicate pred);
|
||||
|
||||
|
||||
template <class lock_type, class Rep, class Period>
|
||||
cv_status wait_for(
|
||||
lock_type& lock,
|
||||
const chrono::duration<Rep, Period>& d);
|
||||
|
||||
template <class lock_type, class Rep, class Period, class Predicate>
|
||||
bool wait_for(
|
||||
lock_type& lock,
|
||||
const chrono::duration<Rep, Period>& d,
|
||||
Predicate pred);
|
||||
|
||||
#if defined BOOST_THREAD_USES_DATETIME
|
||||
template<typename lock_type>
|
||||
bool timed_wait(lock_type& lock,boost::system_time const& abs_time);
|
||||
template<typename lock_type,typename duration_type>
|
||||
bool timed_wait(lock_type& lock,duration_type const& rel_time);
|
||||
template<typename lock_type,typename predicate_type>
|
||||
bool timed_wait(lock_type& lock,boost::system_time const& abs_time,predicate_type predicate);
|
||||
template<typename lock_type,typename duration_type,typename predicate_type>
|
||||
bool timed_wait(lock_type& lock,duration_type const& rel_time,predicate_type predicate);
|
||||
template<typename lock_type>
|
||||
bool timed_wait(lock_type>& lock,boost::xtime const& abs_time);
|
||||
template<typename lock_type,typename predicate_type>
|
||||
bool timed_wait(lock_type& lock,boost::xtime const& abs_time,predicate_type predicate);
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
[section:constructor `condition_variable_any()`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Constructs an object of class `condition_variable_any`.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error occurs.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:destructor `~condition_variable_any()`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Precondition:] [All threads waiting on `*this` have been notified by a call to
|
||||
`notify_one` or `notify_all` (though the respective calls to `wait` or
|
||||
`timed_wait` need not have returned).]]
|
||||
|
||||
[[Effects:] [Destroys the object.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:notify_one `void notify_one()`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If any threads are currently __blocked__ waiting on `*this` in a call
|
||||
to `wait` or `timed_wait`, unblocks one of those threads.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:notify_all `void notify_all()`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If any threads are currently __blocked__ waiting on `*this` in a call
|
||||
to `wait` or `timed_wait`, unblocks all of those threads.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait `template<typename lock_type> void wait(lock_type& lock)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Atomically call `lock.unlock()` and blocks the current thread. The
|
||||
thread will unblock when notified by a call to `this->notify_one()` or
|
||||
`this->notify_all()`, or spuriously. When the thread is unblocked (for whatever
|
||||
reason), the lock is reacquired by invoking `lock.lock()` before the call to
|
||||
`wait` returns. The lock is also reacquired by invoking `lock.lock()` if the
|
||||
function exits with an exception.]]
|
||||
|
||||
[[Postcondition:] [`lock` is locked by the current thread.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error
|
||||
occurs. __thread_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __thread__ object associated with the current thread of execution.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_predicate `template<typename lock_type,typename predicate_type> void wait(lock_type& lock, predicate_type pred)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [As-if ``
|
||||
while(!pred())
|
||||
{
|
||||
wait(lock);
|
||||
}
|
||||
``]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_wait `template<typename lock_type> bool timed_wait(lock_type& lock,boost::system_time const& abs_time)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Atomically call `lock.unlock()` and blocks the current thread. The
|
||||
thread will unblock when notified by a call to `this->notify_one()` or
|
||||
`this->notify_all()`, when the time as reported by `boost::get_system_time()`
|
||||
would be equal to or later than the specified `abs_time`, or spuriously. When
|
||||
the thread is unblocked (for whatever reason), the lock is reacquired by
|
||||
invoking `lock.lock()` before the call to `wait` returns. The lock is also
|
||||
reacquired by invoking `lock.lock()` if the function exits with an exception.]]
|
||||
|
||||
[[Returns:] [`false` if the call is returning because the time specified by
|
||||
`abs_time` was reached, `true` otherwise.]]
|
||||
|
||||
[[Postcondition:] [`lock` is locked by the current thread.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error
|
||||
occurs. __thread_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __thread__ object associated with the current thread of execution.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_wait_rel `template<typename lock_type,typename duration_type> bool timed_wait(lock_type& lock,duration_type const& rel_time)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Atomically call `lock.unlock()` and blocks the current thread. The
|
||||
thread will unblock when notified by a call to `this->notify_one()` or
|
||||
`this->notify_all()`, after the period of time indicated by the `rel_time`
|
||||
argument has elapsed, or spuriously. When the thread is unblocked (for whatever
|
||||
reason), the lock is reacquired by invoking `lock.lock()` before the call to
|
||||
`wait` returns. The lock is also reacquired by invoking `lock.lock()` if the
|
||||
function exits with an exception.]]
|
||||
|
||||
[[Returns:] [`false` if the call is returning because the time period specified
|
||||
by `rel_time` has elapsed, `true` otherwise.]]
|
||||
|
||||
[[Postcondition:] [`lock` is locked by the current thread.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error
|
||||
occurs. __thread_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __thread__ object associated with the current thread of execution.]]
|
||||
|
||||
]
|
||||
|
||||
[note The duration overload of timed_wait is difficult to use correctly. The overload taking a predicate should be preferred in most cases.]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_wait_predicate `template<typename lock_type,typename predicate_type> bool timed_wait(lock_type& lock, boost::system_time const& abs_time, predicate_type pred)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [As-if ``
|
||||
while(!pred())
|
||||
{
|
||||
if(!timed_wait(lock,abs_time))
|
||||
{
|
||||
return pred();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
``]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_until `template <class lock_type, class Clock, class Duration> cv_status wait_until(lock_type& lock, const chrono::time_point<Clock, Duration>& abs_time)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Atomically call `lock.unlock()` and blocks the current thread. The
|
||||
thread will unblock when notified by a call to `this->notify_one()` or
|
||||
`this->notify_all()`, when the time as reported by `Clock::now()`
|
||||
would be equal to or later than the specified `abs_time`, or spuriously. When
|
||||
the thread is unblocked (for whatever reason), the lock is reacquired by
|
||||
invoking `lock.lock()` before the call to `wait` returns. The lock is also
|
||||
reacquired by invoking `lock.lock()` if the function exits with an exception.]]
|
||||
|
||||
[[Returns:] [`cv_status::timeout` if the call is returning because the time specified by
|
||||
`abs_time` was reached, `cv_status::no_timeout` otherwise.]]
|
||||
|
||||
[[Postcondition:] [`lock` is locked by the current thread.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error
|
||||
occurs. __thread_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __thread__ object associated with the current thread of execution.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_for `template <class lock_type, class Rep, class Period> cv_status wait_for(lock_type& lock, const chrono::duration<Rep, Period>& rel_time)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Atomically call `lock.unlock()` and blocks the current thread. The
|
||||
thread will unblock when notified by a call to `this->notify_one()` or
|
||||
`this->notify_all()`, after the period of time indicated by the `rel_time`
|
||||
argument has elapsed, or spuriously. When the thread is unblocked (for whatever
|
||||
reason), the lock is reacquired by invoking `lock.lock()` before the call to
|
||||
`wait` returns. The lock is also reacquired by invoking `lock.lock()` if the
|
||||
function exits with an exception.]]
|
||||
|
||||
[[Returns:] [`cv_status::timeout` if the call is returning because the time specified by
|
||||
`abs_time` was reached, `cv_status::no_timeout` otherwise.]]
|
||||
|
||||
[[Postcondition:] [`lock` is locked by the current thread.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error
|
||||
occurs. __thread_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __thread__ object associated with the current thread of execution.]]
|
||||
|
||||
]
|
||||
|
||||
[note The duration overload of timed_wait is difficult to use correctly. The overload taking a predicate should be preferred in most cases.]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_until_predicate `template <class lock_type, class Clock, class Duration, class Predicate> bool wait_until(lock_type& lock, const chrono::time_point<Clock, Duration>& abs_time, Predicate pred)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [As-if ``
|
||||
while(!pred())
|
||||
{
|
||||
if(!__cvany_wait_until(lock,abs_time))
|
||||
{
|
||||
return pred();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
``]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_for_predicate `template <class lock_type, class Rep, class Period, class Predicate> bool wait_for(lock_type& lock, const chrono::duration<Rep, Period>& rel_time, Predicate pred)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [As-if ``
|
||||
return wait_until(lock, chrono::steady_clock::now() + d, boost::move(pred));
|
||||
``]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:condition Typedef `condition` DEPRECATED V3]
|
||||
|
||||
// #include <boost/thread/condition.hpp>
|
||||
namespace boost
|
||||
{
|
||||
|
||||
typedef condition_variable_any condition;
|
||||
|
||||
}
|
||||
|
||||
The typedef `condition` is provided for backwards compatibility with previous boost releases.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:notify_all_at_thread_exit Non-member Function `notify_all_at_thread_exit`()]
|
||||
|
||||
// #include <boost/thread/condition_variable.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
|
||||
}
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`lk` is locked by the calling thread and either no other thread is waiting on `cond`, or `lk.mutex()` returns the same value for each of the lock arguments supplied by all concurrently waiting (via `wait`, `wait_for`, or `wait_until`) threads.]]
|
||||
[[Effects:] [transfers ownership of the lock associated with `lk` into internal storage and schedules `cond` to be notified when the current thread exits, after all objects of thread storage duration associated with the current thread have been destroyed. This notification shall be as if
|
||||
|
||||
``
|
||||
lk.unlock();
|
||||
cond.notify_all();
|
||||
``
|
||||
|
||||
]]
|
||||
|
||||
]
|
||||
|
||||
[/
|
||||
[[Synchronization:] [The call to notify_all_at_thread_exit and the completion of the destructors for all the current threadÕs variables of thread storage duration synchronize with (1.10) calls to functions waiting on cond.
|
||||
]]
|
||||
[[Note:] [The supplied lock will be held until the thread exits, and care must be taken to ensure that this does not cause deadlock due to lock ordering issues. After calling notify_all_at_thread_exit it is recommended that the thread should be exited as soon as possible, and that no blocking or time-consuming tasks are run on that thread.
|
||||
]]
|
||||
[[Note:] [It is the userÕs responsibility to ensure that waiting threads do not erroneously assume that the thread has finished if they experience spurious wakeups. This typically requires that the condition being waited for is satisfied while holding the lock on lk, and that this lock is not released and reacquired prior to calling notify_all_at_thread_exit.
|
||||
]]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
415
doc/configuration.qbk
Normal file
415
doc/configuration.qbk
Normal file
@@ -0,0 +1,415 @@
|
||||
[/
|
||||
(C) Copyright 20012 Vicente J. Botet Escriba.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
|
||||
[section:configuration Configuration]
|
||||
|
||||
|
||||
[table Default Values for Configurable Features
|
||||
[[Feature] [Anti-Feature] [V2] [V3] [V4] ]
|
||||
[[USES_CHRONO] [DONT_USE_CHRONO] [YES/NO] [YES/NO] [YES/NO] ]
|
||||
[[PROVIDES_INTERRUPTIONS] [DONT_PROVIDE_INTERRUPTIONS] [YES] [YES] [YES] ]
|
||||
[[THROW_IF_PRECONDITION_NOT_SATISFIED] [-] [NO] [NO] [NO] ]
|
||||
|
||||
|
||||
|
||||
[[PROVIDES_PROMISE_LAZY] [DONT_PROVIDE_PROMISE_LAZY] [YES] [NO] [NO] ]
|
||||
|
||||
[[PROVIDES_BASIC_THREAD_ID] [DONT_PROVIDE_BASIC_THREAD_ID] [NO] [YES] [YES] ]
|
||||
[[PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN] [DONT_PROVIDE_GENERIC_SHARED_MUTEX_ON_WIN] [NO] [YES] [YES] ]
|
||||
|
||||
[[PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSION] [DONT_PROVIDE_SHARED_MUTEX_UPWARDS_CONVERSION] [NO] [YES] [YES] ]
|
||||
[[PROVIDES_EXPLICIT_LOCK_CONVERSION] [DONT_PROVIDE_EXPLICIT_LOCK_CONVERSION] [NO] [YES] [YES] ]
|
||||
[[PROVIDES_FUTURE] [DONT_PROVIDE_FUTURE] [NO] [YES] [YES] ]
|
||||
[[PROVIDES_FUTURE_CTOR_ALLOCATORS] [DONT_PROVIDE_FUTURE_CTOR_ALLOCATORS] [NO] [YES] [YES] ]
|
||||
[[PROVIDES_THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE] [DONT_PROVIDE_THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE] [NO] [YES] [YES] ]
|
||||
[[PROVIDES_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE] [DONT_PROVIDE_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE] [NO] [YES] [YES] ]
|
||||
[[PROVIDES_ONCE_CXX11] [DONT_PROVIDE_ONCE_CXX11] [NO] [YES] [YES] ]
|
||||
[[USES_MOVE] [DONT_USE_MOVE] [NO] [YES] [YES] ]
|
||||
|
||||
[[USES_DATETIME] [DONT_USE_DATETIME] [YES/NO] [YES/NO] [YES/NO] ]
|
||||
[[PROVIDES_THREAD_EQ] [DONT_PROVIDE_THREAD_EQ] [YES] [YES] [NO] ]
|
||||
[[PROVIDES_CONDITION] [DONT_PROVIDE_CONDITION] [YES] [YES] [NO] ]
|
||||
[[PROVIDES_NESTED_LOCKS] [DONT_PROVIDE_NESTED_LOCKS] [YES] [YES] [NO] ]
|
||||
[[PROVIDES_SIGNATURE_PACKAGED_TASK] [DONT_PROVIDE_SIGNATURE_PACKAGED_TASK] [NO] [NO] [YES] ]
|
||||
[[PROVIDES_FUTURE_INVALID_AFTER_GET] [DONT_PROVIDE_FUTURE_INVALID_AFTER_GET] [NO] [NO] [YES] ]
|
||||
[/ [[PROVIDES_FUTURE_CONTINUATION] [DONT_PROVIDE_FUTURE_CONTINUATION] [NO] [NO] [YES] ] ]
|
||||
|
||||
[[PROVIDES_VARIADIC_THREAD] [DONT_PROVIDE_VARIADIC_THREAD] [NO] [NO] [C++11] ]
|
||||
|
||||
]
|
||||
|
||||
[section:chrono Boost.Chrono]
|
||||
|
||||
Boost.Thread uses by default Boost.Chrono for the time related functions and define `BOOST_THREAD_USES_CHRONO` if `BOOST_THREAD_DONT_USE_CHRONO` is not defined. The user should define `BOOST_THREAD_DONT_USE_CHRONO` for compilers that don't work well with Boost.Chrono.
|
||||
|
||||
[warning When defined BOOST_THREAD_PLATFORM_WIN32 BOOST_THREAD_USES_CHRONO is defined independently of user settings.]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:move Boost.Move]
|
||||
|
||||
Boost.Thread uses by default an internal move semantic implementation. Since version 3.0.0 you can use the move emulation emulation provided by Boost.Move.
|
||||
|
||||
When `BOOST_THREAD_VERSION==2` define `BOOST_THREAD_USES_MOVE ` if you want to use Boost.Move interface.
|
||||
When `BOOST_THREAD_VERSION>=3` define `BOOST_THREAD_DONT_USE_MOVE ` if you don't want to use Boost.Move interface.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:date_time Boost.DateTime]
|
||||
|
||||
The Boost.DateTime time related functions introduced in Boost 1.35.0, using the [link date_time Boost.Date_Time] library are deprecated. These include (but are not limited to):
|
||||
|
||||
* __sleep__
|
||||
* __timed_join__
|
||||
* __cond_timed_wait__
|
||||
* __timed_lock_ref__
|
||||
|
||||
|
||||
When `BOOST_THREAD_VERSION<=3` && defined BOOST_THREAD_PLATFORM_PTHREAD define `BOOST_THREAD_DONT_USE_DATETIME` if you don't want to use Boost.DateTime related interfaces.
|
||||
When `BOOST_THREAD_VERSION>3` && defined BOOST_THREAD_PLATFORM_PTHREAD define `BOOST_THREAD_USES_DATETIME` if you want to use Boost.DateTime related interfaces.
|
||||
|
||||
[warning When defined BOOST_THREAD_PLATFORM_WIN32 BOOST_THREAD_USES_DATETIME is defined independently of user settings.]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move Boost.Atomic]
|
||||
|
||||
Boost.Thread uses by default an Boost.Atomic in POSIX platforms to implement call_once..
|
||||
|
||||
Define `BOOST_THREAD_USES_ATOMIC ` if you want to use Boost.Atomic.
|
||||
Define `BOOST_THREAD_DONT_USE_ATOMIC ` if you don't want to use Boost.Atomic or if it is not supported in your platform.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:thread_eq `boost::thread::operator==` deprecated]
|
||||
|
||||
The following operators are deprecated:
|
||||
|
||||
* `boost::thread::operator==`
|
||||
* `boost::thread::operator!=`
|
||||
|
||||
When `BOOST_THREAD_PROVIDES_THREAD_EQ` is defined Boost.Thread provides these deprecated feature.
|
||||
|
||||
Use instead
|
||||
|
||||
* `boost::thread::id::operator==`
|
||||
* `boost::thread::id::operator!=`
|
||||
|
||||
[warning This is a breaking change respect to version 1.x.]
|
||||
|
||||
When `BOOST_THREAD_VERSION>=4` define `BOOST_THREAD_PROVIDES_THREAD_EQ ` if you want this feature.
|
||||
When `BOOST_THREAD_VERSION<4` define `BOOST_THREAD_DONT_PROVIDE_THREAD_EQ ` if you don't want this feature.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:condition boost::condition deprecated]
|
||||
|
||||
`boost::condition` is deprecated. When `BOOST_THREAD_PROVIDES_CONDITION` is defined Boost.Thread provides this deprecated feature.
|
||||
|
||||
Use instead `boost::condition_variable_any`.
|
||||
|
||||
[warning This is a breaking change respect to version 1.x.]
|
||||
|
||||
When `BOOST_THREAD_VERSION>3` define `BOOST_THREAD_PROVIDES_CONDITION` if you want this feature.
|
||||
When `BOOST_THREAD_VERSION<=3` define `BOOST_THREAD_DONT_PROVIDE_CONDITION` if you don't want this feature.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:nested_lock Mutex nested lock types deprecated]
|
||||
|
||||
|
||||
The following nested typedefs are deprecated:
|
||||
|
||||
* `boost::mutex::scoped_lock`,
|
||||
* `boost::mutex::scoped_try_lock`,
|
||||
* `boost::timed_mutex::scoped_lock`
|
||||
* `boost::timed_mutex::scoped_try_lock`
|
||||
* `boost::timed_mutex::timed_scoped_timed_lock`
|
||||
* `boost::recursive_mutex::scoped_lock`,
|
||||
* `boost::recursive_mutex::scoped_try_lock`,
|
||||
* `boost::recursive_timed_mutex::scoped_lock`
|
||||
* `boost::recursive_timed_mutex::scoped_try_lock`
|
||||
* `boost::recursive_timed_mutex::timed_scoped_timed_lock`
|
||||
|
||||
When `BOOST_THREAD_PROVIDES_NESTED_LOCKS` is defined Boost.Thread provides these deprecated feature.
|
||||
|
||||
|
||||
Use instead
|
||||
* `boost::unique_lock<boost::mutex>`,
|
||||
* `boost::unique_lock<boost::mutex>` with the `try_to_lock_t` constructor,
|
||||
* `boost::unique_lock<boost::timed_mutex>`
|
||||
* `boost::unique_lock<boost::timed_mutex>` with the `try_to_lock_t` constructor
|
||||
* `boost::unique_lock<boost::timed_mutex>`
|
||||
* `boost::unique_lock<boost::recursive_mutex>`,
|
||||
* `boost::unique_lock<boost::recursive_mutex>` with the `try_to_lock_t` constructor,
|
||||
* `boost::unique_lock<boost::recursive_timed_mutex>`
|
||||
* `boost::unique_lock<boost::recursive_timed_mutex>` with the `try_to_lock_t` constructor
|
||||
* `boost::unique_lock<boost::recursive_timed_mutex>`
|
||||
|
||||
[warning This is a breaking change respect to version 1.x.]
|
||||
|
||||
When `BOOST_THREAD_VERSION>=4` define `BOOST_THREAD_PROVIDES_NESTED_LOCKS` if you want these features.
|
||||
When `BOOST_THREAD_VERSION<4` define `BOOST_THREAD_DONT_PROVIDE_NESTED_LOCKS` if you don't want thes features.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:id thread::id]
|
||||
|
||||
Boost.Thread uses by default a thread::id on Posix based on the pthread type (BOOST_THREAD_PROVIDES_BASIC_THREAD_ID). For backward compatibility and also for compilers that don't work well with this modification the user can define `BOOST_THREAD_DONT_PROVIDE_BASIC_THREAD_ID`.
|
||||
|
||||
Define `BOOST_THREAD_DONT_PROVIDE_BASIC_THREAD_ID ` if you don't want these features.
|
||||
|
||||
[endsect]
|
||||
[section:shared_gen Shared Locking Generic]
|
||||
|
||||
The shared mutex implementation on Windows platform provides currently less functionality than the generic one that is used for PTheads based platforms. In order to have access to these functions, the user needs to define `BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN` to use the generic implementation, that while could be less efficient, provides all the functions.
|
||||
|
||||
When `BOOST_THREAD_VERSION==2` define `BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN ` if you want these features.
|
||||
When `BOOST_THREAD_VERSION>=3` define `BOOST_THREAD_DONT_PROVIDE_GENERIC_SHARED_MUTEX_ON_WIN ` if you don't want these features.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:shared_upwards Shared Locking Upwards Conversion]
|
||||
|
||||
Boost.Threads includes in version 3 the Shared Locking Upwards Conversion as defined in [@http://home.roadrunner.com/~hinnant/bloomington/shared_mutex.html Shared Locking].
|
||||
These conversions need to be used carefully to avoid deadlock or livelock. The user need to define explicitly `BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSION` to get these upwards conversions.
|
||||
|
||||
When `BOOST_THREAD_VERSION==2` define `BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSION ` if you want these features.
|
||||
When `BOOST_THREAD_VERSION>=3` define `BOOST_THREAD_DONT_PROVIDE_SHARED_MUTEX_UPWARDS_CONVERSION ` if you don't want these features.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:explicit_cnv Explicit Lock Conversion]
|
||||
|
||||
In [@http://home.roadrunner.com/~hinnant/bloomington/shared_mutex.html Shared Locking] the lock conversions are explicit. As this explicit conversion breaks the lock interfaces, it is provided only if the `BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION` is defined.
|
||||
|
||||
When `BOOST_THREAD_VERSION==2` define `BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION ` if you want these features.
|
||||
When `BOOST_THREAD_VERSION==3` define `BOOST_THREAD_DONT_PROVIDE_EXPLICIT_LOCK_CONVERSION ` if you don't want these features.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:future unique_future versus future]
|
||||
|
||||
C++11 uses `std::future`. Versions of Boost.Thread previous to version 3.0.0 uses `boost:unique_future`.
|
||||
Since version 3.0.0 `boost::future` replaces `boost::unique_future` when `BOOST_THREAD_PROVIDES_FUTURE` is defined. The documentation doesn't contains anymore however `boost::unique_future`.
|
||||
|
||||
When `BOOST_THREAD_VERSION==2` define `BOOST_THREAD_PROVIDES_FUTURE` if you want to use boost::future.
|
||||
When `BOOST_THREAD_VERSION>=3` define `BOOST_THREAD_DONT_PROVIDE_FUTURE` if you want to use boost::unique_future.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:lazy promise lazy initialization]
|
||||
|
||||
C++11 promise initialize the associated state at construction time. Versions of Boost.Thread previous to version 3.0.0 initialize it lazily at any point in time in which this associated state is needed.
|
||||
|
||||
Since version 3.0.0 this difference in behavior can be configured. When `BOOST_THREAD_PROVIDES_PROMISE_LAZY` is defined the backward compatible behavior is provided.
|
||||
|
||||
When `BOOST_THREAD_VERSION==2` define `BOOST_THREAD_DONT_PROVIDE_PROMISE_LAZY ` if you want to use boost::future.
|
||||
When `BOOST_THREAD_VERSION>=3` define `BOOST_THREAD_PROVIDES_PROMISE_LAZY ` if you want to use boost::unique_future.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:alloc promise Allocator constructor]
|
||||
|
||||
C++11 std::promise provides constructors with allocators.
|
||||
|
||||
template <typename R>
|
||||
class promise
|
||||
{
|
||||
public:
|
||||
template <class Allocator>
|
||||
explicit promise(allocator_arg_t, Allocator a);
|
||||
// ...
|
||||
};
|
||||
template <class R, class Alloc> struct uses_allocator<promise<R>,Alloc>: true_type {};
|
||||
|
||||
where
|
||||
|
||||
struct allocator_arg_t { };
|
||||
constexpr allocator_arg_t allocator_arg = allocator_arg_t();
|
||||
|
||||
template <class T, class Alloc> struct uses_allocator;
|
||||
|
||||
Since version 3.0.0 Boost.Thread implements this constructor using the following interface
|
||||
|
||||
namespace boost
|
||||
{
|
||||
typedef container::allocator_arg_t allocator_arg_t;
|
||||
constexpr allocator_arg_t allocator_arg = {};
|
||||
|
||||
namespace container
|
||||
{
|
||||
template <class R, class Alloc>
|
||||
struct uses_allocator<promise<R>,Alloc>: true_type {};
|
||||
}
|
||||
template <class T, class Alloc>
|
||||
struct uses_allocator : public container::uses_allocator<T, Alloc> {};
|
||||
}
|
||||
|
||||
which introduces a dependency on Boost.Container. This feature is provided only if `BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS` is defined.
|
||||
|
||||
When `BOOST_THREAD_VERSION==2` define `BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS ` if you want these features.
|
||||
When `BOOST_THREAD_VERSION>=3` define `BOOST_THREAD_DONT_PROVIDE_FUTURE_CTOR_ALLOCATORS ` if you don't want these features.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:terminate Call to terminate if joinable]
|
||||
|
||||
C++11 has a different semantic for the thread destructor and the move assignment. Instead of detaching the thread, calls to terminate() if the thread was joinable. When `BOOST_THREAD_PROVIDES_THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE` and `BOOST_THREAD_PROVIDES_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE` is defined Boost.Thread provides the C++ semantic.
|
||||
|
||||
When `BOOST_THREAD_VERSION==2` define `BOOST_THREAD_PROVIDES_THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE ` if you want these features.
|
||||
When `BOOST_THREAD_VERSION>=3` define `BOOST_THREAD_DONT_PROVIDE_THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE ` if you don't want these features.
|
||||
|
||||
When `BOOST_THREAD_VERSION==2` define `BOOST_THREAD_PROVIDES_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE ` if you want these features.
|
||||
When `BOOST_THREAD_VERSION>=3` define `BOOST_THREAD_DONT_PROVIDE_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE ` if you don't want these features.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:once_flag once_flag]
|
||||
|
||||
C++11 defines a default constructor for once_flag. When `BOOST_THREAD_PROVIDES_ONCE_CXX11 ` is defined Boost.Thread provides this C++ semantics. In this case, the previous aggregate syntax is not supported.
|
||||
|
||||
boost::once_flag once = BOOST_ONCE_INIT;
|
||||
|
||||
You should now just do
|
||||
|
||||
boost::once_flag once;
|
||||
|
||||
When `BOOST_THREAD_VERSION==2` define `BOOST_THREAD_PROVIDES_ONCE_CXX11` if you want these features.
|
||||
When `BOOST_THREAD_VERSION>=3` define `BOOST_THREAD_DONT_PROVIDE_ONCE_CXX11` if you don't want these features.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:deprecated Signature parameter for packaged_task]
|
||||
|
||||
C++11 packaged task class has a Signature template parameter. When `BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK ` is defined Boost.Thread provides this C++ feature.
|
||||
|
||||
[warning This is a breaking change respect to version 3.x.]
|
||||
|
||||
When `BOOST_THREAD_VERSION<4` define `BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK` if you want this feature.
|
||||
When `BOOST_THREAD_VERSION>=4` define `BOOST_THREAD_DONT_PROVIDE_SIGNATURE_PACKAGED_TASK` if you don't want this feature.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:thread_const-var thread constructor with variadic rvalue parameters]
|
||||
|
||||
C++11 thread constructor accep a variable number of rvalue argumentshas. When `BOOST_THREAD_PROVIDES_VARIADIC_THREAD ` is defined Boost.Thread provides this C++ feature if the following are not defined
|
||||
|
||||
* BOOST_NO_SFINAE_EXPR
|
||||
* BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
||||
* BOOST_NO_CXX11_DECLTYPE
|
||||
* BOOST_NO_CXX11_DECLTYPE_N3276
|
||||
* BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
* BOOST_NO_CXX11_TRAILING_RESULT_TYPES
|
||||
* BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
* BOOST_NO_CXX11_HDR_TUPLE
|
||||
|
||||
When `BOOST_THREAD_VERSION>4` define `BOOST_THREAD_DONT_PROVIDE_VARIADIC_THREAD ` if you don't want this feature.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:get_invalid future<>::get() invalidates the future]
|
||||
|
||||
C++11 future<>::get() invalidates the future once its value has been obtained. When `BOOST_THREAD_PROVIDES_FUTURE_INVALID_AFTER_GET ` is defined Boost.Thread provides this C++ feature.
|
||||
|
||||
[warning This is a breaking change respect to version 3.x.]
|
||||
|
||||
When `BOOST_THREAD_VERSION<4` define `BOOST_THREAD_PROVIDES_FUTURE_INVALID_AFTER_GET` if you want this feature.
|
||||
When `BOOST_THREAD_VERSION>=4` define `BOOST_THREAD_DONT_PROVIDE_FUTURE_INVALID_AFTER_GET` if you don't want this feature.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:intr Interruptions]
|
||||
|
||||
Thread interruption, while useful, makes any interruption point less efficient than if the thread were not interruptible.
|
||||
|
||||
When `BOOST_THREAD_PROVIDES_INTERRUPTIONS` is defined Boost.Thread provides interruptions.
|
||||
When `BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS` is defined Boost.Thread don't provide interruption.
|
||||
|
||||
Boost.Thread defines BOOST_THREAD_PROVIDES_INTERRUPTIONS if neither BOOST_THREAD_PROVIDES_INTERRUPTIONS nor BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS are defined, so that there is no compatibility break.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:version Version]
|
||||
|
||||
`BOOST_THREAD_VERSION` defines the Boost.Thread version.
|
||||
The default version is 2. In this case the following breaking or extending macros are defined if the opposite is not requested:
|
||||
|
||||
* `BOOST_THREAD_PROVIDES_PROMISE_LAZY`
|
||||
|
||||
The user can request the version 3 by defining `BOOST_THREAD_VERSION` to 3. In this case the following breaking or extending macros are defined if the opposite is not requested:
|
||||
|
||||
* Breaking change `BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION `
|
||||
* Conformity & Breaking change `BOOST_THREAD_PROVIDES_FUTURE`
|
||||
* Uniformity `BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN`
|
||||
* Extension `BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSION`
|
||||
* Conformity `BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS`
|
||||
* Conformity & Breaking change BOOST_THREAD_PROVIDES_THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE
|
||||
* Conformity & Breaking change BOOST_THREAD_PROVIDES_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE
|
||||
* Conformity & Breaking change `BOOST_THREAD_PROVIDES_ONCE_CXX11`
|
||||
|
||||
* Breaking change `BOOST_THREAD_DONT_PROVIDE_PROMISE_LAZY`
|
||||
|
||||
[/The default value for `BOOST_THREAD_VERSION` will be changed to 3 since Boost 1.54.]
|
||||
|
||||
The user can request the version 4 by defining `BOOST_THREAD_VERSION` to 4. In this case the following breaking or extending macros are defined if the opposite is not requested:
|
||||
|
||||
* Conformity & Breaking change `BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK `
|
||||
* Conformity & Breaking change `BOOST_THREAD_PROVIDES_FUTURE_INVALID_AFTER_GET `
|
||||
* Conformity `BOOST_THREAD_PROVIDES_VARIADIC_THREAD`
|
||||
* Breaking change `BOOST_THREAD_DONT_PROVIDE_THREAD_EQ`
|
||||
* Breaking change `BOOST_THREAD_DONT_USE_DATETIME`
|
||||
|
||||
|
||||
[/The default value for `BOOST_THREAD_VERSION` will be changed to 4 since Boost 1.58.]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:limitations Limitations]
|
||||
|
||||
Some compilers don't work correctly with some of the added features.
|
||||
|
||||
[section:sun SunPro]
|
||||
|
||||
If __SUNPRO_CC < 0x5100 the library defines
|
||||
|
||||
* `BOOST_THREAD_DONT_USE_MOVE`
|
||||
|
||||
If __SUNPRO_CC < 0x5100 the library defines
|
||||
|
||||
* `BOOST_THREAD_DONT_PROVIDE_FUTURE_CTOR_ALLOCATORS`
|
||||
|
||||
|
||||
[endsect]
|
||||
[section:vacpp VACPP]
|
||||
|
||||
If __IBMCPP__ < 1100 the library defines
|
||||
|
||||
* `BOOST_THREAD_DONT_USE_CHRONO`
|
||||
* `BOOST_THREAD_USES_DATE`
|
||||
|
||||
And Boost.Thread doesn't links with Boost.Chrono.
|
||||
|
||||
|
||||
[endsect]
|
||||
[section:ce WCE]
|
||||
|
||||
If _WIN32_WCE && _WIN32_WCE==0x501 the library defines
|
||||
|
||||
* `BOOST_THREAD_DONT_PROVIDE_FUTURE_CTOR_ALLOCATORS`
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
@@ -1,96 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.configuration" last-revision="$Date$">
|
||||
<title>Configuration</title>
|
||||
<para>&Boost.Thread; uses several configuration macros in <boost/config.hpp>,
|
||||
as well as configuration macros meant to be supplied by the application. These
|
||||
macros are documented here.
|
||||
</para>
|
||||
<section id="thread.configuration.public">
|
||||
<title>Library Defined Public Macros</title>
|
||||
<para>
|
||||
These macros are defined by &Boost.Thread; but are expected to be used
|
||||
by application code.
|
||||
</para>
|
||||
<informaltable>
|
||||
<tgroup cols="2">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Macro</entry>
|
||||
<entry>Meaning</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>BOOST_HAS_THREADS</entry>
|
||||
<entry>
|
||||
Indicates that threading support is available. This means both that there
|
||||
is a platform specific implementation for &Boost.Thread; and that
|
||||
threading support has been enabled in a platform specific manner. For instance,
|
||||
on the Win32 platform there's an implementation for &Boost.Thread;
|
||||
but unless the program is compiled against one of the multithreading runtimes
|
||||
(often determined by the compiler predefining the macro _MT) the BOOST_HAS_THREADS
|
||||
macro remains undefined.
|
||||
</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
</section>
|
||||
<section id="thread.configuration.implementation">
|
||||
<title>Library Defined Implementation Macros</title>
|
||||
<para>
|
||||
These macros are defined by &Boost.Thread; and are implementation details
|
||||
of interest only to implementors.
|
||||
</para>
|
||||
<informaltable>
|
||||
<tgroup cols="2">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Macro</entry>
|
||||
<entry>Meaning</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>BOOST_HAS_WINTHREADS</entry>
|
||||
<entry>
|
||||
Indicates that the platform has the Microsoft Win32 threading libraries,
|
||||
and that they should be used to implement &Boost.Thread;.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>BOOST_HAS_PTHREADS</entry>
|
||||
<entry>
|
||||
Indicates that the platform has the POSIX pthreads libraries, and that
|
||||
they should be used to implement &Boost.Thread;.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>BOOST_HAS_FTIME</entry>
|
||||
<entry>
|
||||
Indicates that the implementation should use GetSystemTimeAsFileTime()
|
||||
and the FILETIME type to calculate the current time. This is an implementation
|
||||
detail used by boost::detail::getcurtime().
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>BOOST_HAS_GETTTIMEOFDAY</entry>
|
||||
<entry>
|
||||
Indicates that the implementation should use gettimeofday() to calculate
|
||||
the current time. This is an implementation detail used by boost::detail::getcurtime().
|
||||
</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
</section>
|
||||
</section>
|
||||
159
doc/design.xml
159
doc/design.xml
@@ -1,159 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.design" last-revision="$Date$">
|
||||
<title>Design</title>
|
||||
<para>With client/server and three-tier architectures becoming common place
|
||||
in today's world, it's becoming increasingly important for programs to be
|
||||
able to handle parallel processing. Modern day operating systems usually
|
||||
provide some support for this through native thread APIs. Unfortunately,
|
||||
writing portable code that makes use of parallel processing in C++ is made
|
||||
very difficult by a lack of a standard interface for these native APIs.
|
||||
Further, these APIs are almost universally C APIs and fail to take
|
||||
advantage of C++'s strengths, or to address concepts unique to C++, such as
|
||||
exceptions.</para>
|
||||
<para>The &Boost.Thread; library is an attempt to define a portable interface
|
||||
for writing parallel processes in C++.</para>
|
||||
<section id="thread.design.goals">
|
||||
<title>Goals</title>
|
||||
<para>The &Boost.Thread; library has several goals that should help to set
|
||||
it apart from other solutions. These goals are listed in order of precedence
|
||||
with full descriptions below.
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>Portability</term>
|
||||
<listitem>
|
||||
<para>&Boost.Thread; was designed to be highly portable. The goal is
|
||||
for the interface to be easily implemented on any platform that
|
||||
supports threads, and possibly even on platforms without native thread
|
||||
support.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Safety</term>
|
||||
<listitem>
|
||||
<para>&Boost.Thread; was designed to be as safe as possible. Writing
|
||||
<link linkend="thread.glossary.thread-safe">thread-safe</link>
|
||||
code is very difficult and successful libraries must strive to
|
||||
insulate the programmer from dangerous constructs as much as
|
||||
possible. This is accomplished in several ways:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>C++ language features are used to make correct usage easy
|
||||
(if possible) and error-prone usage impossible or at least more
|
||||
difficult. For example, see the <link
|
||||
linkend="thread.concepts.Mutex">Mutex</link> and <link
|
||||
linkend="thread.concepts.Lock">Lock</link> designs, and note
|
||||
how they interact.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Certain traditional concurrent programming features are
|
||||
considered so error-prone that they are not provided at all. For
|
||||
example, see <xref linkend="thread.rationale.events" />.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Dangerous features, or features which may be misused, are
|
||||
identified as such in the documentation to make users aware of
|
||||
potential pitfalls.</para>
|
||||
</listitem>
|
||||
</itemizedlist></para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Flexibility</term>
|
||||
<listitem>
|
||||
<para>&Boost.Thread; was designed to be flexible. This goal is often
|
||||
at odds with <emphasis>safety</emphasis>. When functionality might be
|
||||
compromised by the desire to keep the interface safe, &Boost.Thread;
|
||||
has been designed to provide the functionality, but to make it's use
|
||||
prohibitive for general use. In other words, the interfaces have been
|
||||
designed such that it's usually obvious when something is unsafe, and
|
||||
the documentation is written to explain why.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>Efficiency</term>
|
||||
<listitem>
|
||||
<para>&Boost.Thread; was designed to be as efficient as
|
||||
possible. When building a library on top of another library there is
|
||||
always a danger that the result will be so much slower than the
|
||||
"native" API that programmers are inclined to ignore the higher level
|
||||
API. &Boost.Thread; was designed to minimize the chances of this
|
||||
occurring. The interfaces have been crafted to allow an implementation
|
||||
the greatest chance of being as efficient as possible. This goal is
|
||||
often at odds with the goal for <emphasis>safety</emphasis>. Every
|
||||
effort was made to ensure efficient implementations, but when in
|
||||
conflict <emphasis>safety</emphasis> has always taken
|
||||
precedence.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist></para>
|
||||
</section>
|
||||
<section>
|
||||
<title>Iterative Phases</title>
|
||||
<para>Another goal of &Boost.Thread; was to take a dynamic, iterative
|
||||
approach in its development. The computing industry is still exploring the
|
||||
concepts of parallel programming. Most thread libraries supply only simple
|
||||
primitive concepts for thread synchronization. These concepts are very
|
||||
simple, but it is very difficult to use them safely or to provide formal
|
||||
proofs for constructs built on top of them. There has been a lot of research
|
||||
into other concepts, such as in "Communicating Sequential Processes."
|
||||
&Boost.Thread; was designed in iterative steps, with each step providing
|
||||
the building blocks necessary for the next step and giving the researcher
|
||||
the tools necessary to explore new concepts in a portable manner.</para>
|
||||
<para>Given the goal of following a dynamic, iterative approach
|
||||
&Boost.Thread; shall go through several growth cycles. Each phase in its
|
||||
development shall be roughly documented here.</para>
|
||||
</section>
|
||||
<section>
|
||||
<title>Phase 1, Synchronization Primitives</title>
|
||||
<para>Boost is all about providing high quality libraries with
|
||||
implementations for many platforms. Unfortunately, there's a big problem
|
||||
faced by developers wishing to supply such high quality libraries, namely
|
||||
thread-safety. The C++ standard doesn't address threads at all, but real
|
||||
world programs often make use of native threading support. A portable
|
||||
library that doesn't address the issue of thread-safety is therefore not
|
||||
much help to a programmer who wants to use the library in his multithreaded
|
||||
application. So there's a very great need for portable primitives that will
|
||||
allow the library developer to create <link
|
||||
linkend="thread.glossary.thread-safe">thread-safe</link>
|
||||
implementations. This need far out weighs the need for portable methods to
|
||||
create and manage threads.</para>
|
||||
<para>Because of this need, the first phase of &Boost.Thread; focuses
|
||||
solely on providing portable primitive concepts for thread
|
||||
synchronization. Types provided in this phase include the
|
||||
<classname>boost::mutex</classname>,
|
||||
<classname>boost::try_mutex</classname>,
|
||||
<classname>boost::timed_mutex</classname>,
|
||||
<classname>boost::recursive_mutex</classname>,
|
||||
<classname>boost::recursive_try_mutex</classname>,
|
||||
<classname>boost::recursive_timed_mutex</classname>, and
|
||||
<classname>boost::lock_error</classname>. These are considered the "core"
|
||||
synchronization primitives, though there are others that will be added in
|
||||
later phases.</para>
|
||||
</section>
|
||||
<section id="thread.design.phase2">
|
||||
<title>Phase 2, Thread Management and Thread Specific Storage</title>
|
||||
<para>This phase addresses the creation and management of threads and
|
||||
provides a mechanism for thread specific storage (data associated with a
|
||||
thread instance). Thread management is a tricky issue in C++, so this
|
||||
phase addresses only the basic needs of multithreaded program. Later
|
||||
phases are likely to add additional functionality in this area. This
|
||||
phase of &Boost.Thread; adds the <classname>boost::thread</classname> and
|
||||
<classname>boost::thread_specific_ptr</classname> types. With these
|
||||
additions the &Boost.Thread; library can be considered minimal but
|
||||
complete.</para>
|
||||
</section>
|
||||
<section>
|
||||
<title>The Next Phase</title>
|
||||
<para>The next phase will address more advanced synchronization concepts,
|
||||
such as read/write mutexes and barriers.</para>
|
||||
</section>
|
||||
</section>
|
||||
365
doc/emulations.qbk
Normal file
365
doc/emulations.qbk
Normal file
@@ -0,0 +1,365 @@
|
||||
[/
|
||||
(C) Copyright 20012 Vicente J. Botet Escriba.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
|
||||
[section:emulations Emulations]
|
||||
[section:delete `=delete` emulation]
|
||||
|
||||
C++11 allows to delete some implicitly generated functions as constructors and assignment using '= delete' as in
|
||||
|
||||
public:
|
||||
thread(thread const&) = delete;
|
||||
|
||||
On compilers not supporting this feature, Boost.Thread relays on a partial simulation, it declares the function as private without definition.
|
||||
|
||||
private:
|
||||
thread(thread &);
|
||||
|
||||
The emulation is partial as the private function can be used for overload resolution for some compilers and prefer it to other overloads that need a conversion. See below the consequences on the move semantic emulation.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move Move semantics]
|
||||
|
||||
In order to implement Movable classes, move parameters and return types Boost.Thread uses the rvalue reference when the compiler support it.
|
||||
On compilers not supporting it Boost.Thread uses either the emulation provided by Boost.Move or the emulation provided by the previous versions of Boost.Thread depending whether `BOOST_THREAD_USES_MOVE` is defined or not. This macros is unset by default when `BOOST_THREAD_VERSION` is 2. Since `BOOST_THREAD_VERSION` 3, `BOOST_THREAD_USES_MOVE` is defined.
|
||||
|
||||
[section:deprecated Deprecated Version 2 interface]
|
||||
|
||||
Previous to version 1.50, Boost.Thread make use of its own move semantic emulation which had more limitations than the provided by Boost.Move. In addition, it is of interest of the whole Boost community that Boost.Thread uses Boost.Move so that boost::thread can be stored on Movable aware containers.
|
||||
|
||||
To preserve backward compatibility at least during some releases, Boost.Thread allows the user to use the deprecated move semantic emulation defining BOOST_THREAD_DONT_USE_MOVE.
|
||||
|
||||
Many aspects of move semantics can be emulated for compilers not supporting rvalue references and Boost.Thread legacy offers tools for that purpose.
|
||||
|
||||
[section:Helper Helpers class and function]
|
||||
|
||||
Next follows the interface of the legacy move semantic helper class and function.
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template<typename T>
|
||||
struct thread_move_t
|
||||
{
|
||||
explicit thread_move_t(T& t_);
|
||||
T& operator*() const;
|
||||
T* operator->() const;
|
||||
private:
|
||||
void operator=(thread_move_t&);
|
||||
};
|
||||
}
|
||||
template<typename T>
|
||||
boost::detail::thread_move_t<T> move(boost::detail::thread_move_t<T> t);
|
||||
}
|
||||
[endsect]
|
||||
|
||||
[section:movable Movable emulation]
|
||||
|
||||
We can write a MovableOny class as follows. You just need to follow these simple steps:
|
||||
|
||||
* Add a conversion to the `detail::thread_move_t<classname>`
|
||||
* Make the copy constructor private.
|
||||
* Write a constructor taking the parameter as `detail::thread_move_t<classname>`
|
||||
* Write an assignment taking the parameter as `detail::thread_move_t<classname>`
|
||||
|
||||
For example the thread class defines the following:
|
||||
|
||||
class thread
|
||||
{
|
||||
// ...
|
||||
private:
|
||||
thread(thread&);
|
||||
thread& operator=(thread&);
|
||||
public:
|
||||
detail::thread_move_t<thread> move()
|
||||
{
|
||||
detail::thread_move_t<thread> x(*this);
|
||||
return x;
|
||||
}
|
||||
operator detail::thread_move_t<thread>()
|
||||
{
|
||||
return move();
|
||||
}
|
||||
thread(detail::thread_move_t<thread> x)
|
||||
{
|
||||
thread_info=x->thread_info;
|
||||
x->thread_info.reset();
|
||||
}
|
||||
thread& operator=(detail::thread_move_t<thread> x)
|
||||
{
|
||||
thread new_thread(x);
|
||||
swap(new_thread);
|
||||
return *this;
|
||||
}
|
||||
// ...
|
||||
|
||||
};
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:portable Portable interface]
|
||||
|
||||
In order to make the library code portable Boost.Thread uses some macros that will use either the ones provided by Boost.Move or the deprecated move semantics provided by previous versions of Boost.Thread.
|
||||
|
||||
See the Boost.Move documentation for a complete description on how to declare new Movable classes and its limitations.
|
||||
|
||||
* `BOOST_THREAD_RV_REF(TYPE)` is the equivalent of `BOOST_RV_REF(TYPE)`
|
||||
* `BOOST_THREAD_RV_REF_BEG` is the equivalent of `BOOST_RV_REF_BEG(TYPE)`
|
||||
* `BOOST_THREAD_RV_REF_END` is the equivalent of `BOOST_RV_REF_END(TYPE)`
|
||||
* `BOOST_THREAD_FWD_REF(TYPE)` is the equivalent of `BOOST_FWD_REF(TYPE)
|
||||
|
||||
In addition the following macros are needed to make the code portable:
|
||||
|
||||
* `BOOST_THREAD_RV(V)` macro to access the rvalue from a BOOST_THREAD_RV_REF(TYPE),
|
||||
* `BOOST_THREAD_MAKE_RV_REF(RVALUE)` makes a rvalue.
|
||||
* `BOOST_THREAD_DCL_MOVABLE(CLASS)` to avoid conflicts with Boost.Move
|
||||
* `BOOST_THREAD_DCL_MOVABLE_BEG(T1)` and `BOOST_THREAD_DCL_MOVABLE_END` are variant of `BOOST_THREAD_DCL_MOVABLE` when the parameter is a template instantiation.
|
||||
|
||||
Other macros are provided and must be included on the public section:
|
||||
|
||||
* `BOOST_THREAD_NO_COPYABLE` declares a class no-copyable either deleting the copy constructors and copy assignment or moving them to the private section.
|
||||
* `BOOST_THREAD_MOVABLE(CLASS)` declares all the implicit conversions to an rvalue-reference.
|
||||
* `BOOST_THREAD_MOVABLE_ONLY(CLASS)` is the equivalent of `BOOST_MOVABLE_BUT_NOT_COPYABLE(CLASS)`
|
||||
* `BOOST_THREAD_COPYABLE_AND_MOVABLE(CLASS)` is the equivalent of `BOOST_COPYABLE_AND_MOVABLE(CLASS)`
|
||||
|
||||
|
||||
[section:NO_COPYABLE `BOOST_THREAD_NO_COPYABLE(CLASS)`]
|
||||
|
||||
This macro marks a class as no copyable, disabling copy construction and assignment.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:MOVABLE `BOOST_THREAD_MOVABLE(CLASS)`]
|
||||
|
||||
This macro marks a class as movable, declaring all the implicit conversions to an rvalue-reference.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:MOVABLE_ONLY `BOOST_THREAD_MOVABLE_ONLY(CLASS)`]
|
||||
|
||||
This macro marks a type as movable but not copyable, disabling copy construction and assignment. The user will need to write a move constructor/assignment to fully write a movable but not copyable class.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:COPYABLE_AND_MOVABLE `BOOST_THREAD_COPYABLE_AND_MOVABLE(CLASS)`]
|
||||
|
||||
This macro marks a type as copyable and movable. The user will need to write a move constructor/assignment and a copy assignment to fully write a copyable and movable class.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:RV_REF `BOOST_THREAD_RV_REF(TYPE)`, `BOOST_THREAD_RV_REF_BEG` and `BOOST_THREAD_RV_REF_END`]
|
||||
|
||||
This macro is used to achieve portable syntax in move constructors and assignments for classes marked as `BOOST_THREAD_COPYABLE_AND_MOVABLE` or `BOOST_THREAD_MOVABLE_ONLY`.
|
||||
|
||||
`BOOST_THREAD_RV_REF_BEG` and `BOOST_THREAD_RV_REF_END` are used when the parameter end with a `>` to avoid the compiler error.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:RV `BOOST_THREAD_RV(V)`]
|
||||
|
||||
While Boost.Move emulation allows to access an rvalue reference `BOOST_THREAD_RV_REF(TYPE)` using the dot operator, the legacy defines the `operator->`. We need then a macro `BOOST_THREAD_RV` that mask this difference. E.g.
|
||||
|
||||
thread(BOOST_THREAD_RV_REF(thread) x)
|
||||
{
|
||||
thread_info=BOOST_THREAD_RV(x).thread_info;
|
||||
BOOST_THREAD_RV(x).thread_info.reset();
|
||||
}
|
||||
|
||||
The use of this macros has reduced considerably the size of the Boost.Thread move related code.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:MAKE_RV_REF `BOOST_THREAD_MAKE_RV_REF(RVALUE)`]
|
||||
|
||||
While Boost.Move is the best C++03 move emulation there are some limitations that impact the way the library can be used.
|
||||
For example, with the following declarations
|
||||
|
||||
class thread {
|
||||
// ...
|
||||
private:
|
||||
thread(thread &);
|
||||
public:
|
||||
thread(rv<thread>&);
|
||||
// ...
|
||||
};
|
||||
|
||||
This could not work on some compilers even if thread is convertible to `rv<thread>` because the compiler prefers the private copy constructor.
|
||||
|
||||
thread mkth()
|
||||
{
|
||||
return thread(f);
|
||||
}
|
||||
|
||||
On these compilers we need to use instead an explicit conversion. The library provides a move member function that allows to workaround the issue.
|
||||
|
||||
thread mkth()
|
||||
{
|
||||
return thread(f).move();
|
||||
}
|
||||
|
||||
Note that `::boost::move` can not be used in this case as thread is not implicitly convertible to `thread&`.
|
||||
|
||||
thread mkth()
|
||||
{
|
||||
return ::boost::move(thread(f));
|
||||
}
|
||||
|
||||
To make the code portable Boost.Thread the user needs to use a macro `BOOST_THREAD_MAKE_RV_REF` that can be used as in
|
||||
|
||||
thread mkth()
|
||||
{
|
||||
return BOOST_THREAD_MAKE_RV_REF(thread(f));
|
||||
}
|
||||
|
||||
Note that this limitation is shared also by the legacy Boost.Thread move emulation.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:DCL_MOVABLE `BOOST_THREAD_DCL_MOVABLE`, `BOOST_THREAD_DCL_MOVABLE_BEG(T1)` and `BOOST_THREAD_DCL_MOVABLE_END`]
|
||||
|
||||
As Boost.Move defines also the `boost::move` function we need to specialize the `has_move_emulation_enabled_aux` metafunction.
|
||||
|
||||
template <>
|
||||
struct has_move_emulation_enabled_aux<thread>
|
||||
: BOOST_MOVE_BOOST_NS::integral_constant<bool, true>
|
||||
{};
|
||||
|
||||
so that the following Boost.Move overload is disabled
|
||||
|
||||
template <class T>
|
||||
inline typename BOOST_MOVE_BOOST_NS::disable_if<has_move_emulation_enabled_aux<T>, T&>::type move(T& x);
|
||||
|
||||
The macros `BOOST_THREAD_DCL_MOVABLE(CLASS)`, `BOOST_THREAD_DCL_MOVABLE_BEG(T1)` and `BOOST_THREAD_DCL_MOVABLE_END` are used for this purpose. E.g.
|
||||
|
||||
BOOST_THREAD_DCL_MOVABLE(thread)
|
||||
|
||||
and
|
||||
|
||||
BOOST_THREAD_DCL_MOVABLE_BEG(T) promise<T> BOOST_THREAD_DCL_MOVABLE_END
|
||||
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:bool_explicit_conversion Bool explicit conversion]
|
||||
|
||||
Locks provide an explicit bool conversion operator when the compiler provides them.
|
||||
|
||||
explicit operator bool() const;
|
||||
|
||||
The library provides un implicit conversion to an undefined type that can be used as a conditional expression.
|
||||
|
||||
#if defined(BOOST_NO_EXPLICIT_CONVERSION_OPERATORS)
|
||||
operator ``['unspecified-bool-type]``() const;
|
||||
bool operator!() const;
|
||||
#else
|
||||
explicit operator bool() const;
|
||||
#endif
|
||||
|
||||
The user should use the lock.owns_lock() when a explicit conversion is required.
|
||||
|
||||
[section:bool_conversion `operator `['unspecified-bool-type]`() const`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Returns:] [If __owns_lock_ref__ would return `true`, a value that evaluates to
|
||||
`true` in boolean contexts, otherwise a value that evaluates to `false` in
|
||||
boolean contexts.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:operator_not `bool operator!() const`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Returns:] [`!` __owns_lock_ref__.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:scoped_enums Scoped Enums]
|
||||
|
||||
Some of the enumerations defined in the standard library are scoped enums.
|
||||
|
||||
On compilers that don't support them, the library uses a class to wrap the underlying type. Instead of
|
||||
|
||||
enum class future_errc
|
||||
{
|
||||
broken_promise,
|
||||
future_already_retrieved,
|
||||
promise_already_satisfied,
|
||||
no_state
|
||||
};
|
||||
|
||||
the library declare these types as
|
||||
|
||||
BOOST_SCOPED_ENUM_DECLARE_BEGIN(future_errc)
|
||||
{
|
||||
broken_promise,
|
||||
future_already_retrieved,
|
||||
promise_already_satisfied,
|
||||
no_state
|
||||
}
|
||||
BOOST_SCOPED_ENUM_DECLARE_END(future_errc)
|
||||
|
||||
These macros allows to use 'future_errc' in almost all the cases as an scoped enum.
|
||||
|
||||
There are however some limitations:
|
||||
|
||||
* The type is not a C++ enum, so 'is_enum<future_errc>' will be false_type.
|
||||
* The emulated scoped enum can not be used in switch nor in template arguments. For these cases the user needs to use some macros.
|
||||
|
||||
Instead of
|
||||
|
||||
switch (ev)
|
||||
{
|
||||
case future_errc::broken_promise:
|
||||
// ...
|
||||
|
||||
use
|
||||
|
||||
switch (boost::native_value(ev))
|
||||
{
|
||||
case future_errc::broken_promise:
|
||||
|
||||
And instead of
|
||||
|
||||
#ifdef BOOST_NO_SCOPED_ENUMS
|
||||
template <>
|
||||
struct BOOST_SYMBOL_VISIBLE is_error_code_enum<future_errc> : public true_type { };
|
||||
#endif
|
||||
|
||||
use
|
||||
|
||||
#ifdef BOOST_NO_SCOPED_ENUMS
|
||||
template <>
|
||||
struct BOOST_SYMBOL_VISIBLE is_error_code_enum<future_errc::enum_type> : public true_type { };
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
@@ -1,31 +0,0 @@
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<!ENTITY Boost "<emphasis role='bold'>Boost</emphasis>">
|
||||
<!ENTITY Boost.Thread "<emphasis role='bold'>Boost.Thread</emphasis>">
|
||||
<!ENTITY Boost.Build "<emphasis role='bold'>Boost.Build</emphasis>">
|
||||
<!ENTITY cite.AndrewsSchneider83 "<citation><xref
|
||||
linkend='thread.bib.AndrewsSchneider83'
|
||||
endterm='thread.bib.AndrewsSchneider83.abbrev'/></citation>">
|
||||
<!ENTITY cite.Boost "<citation><xref linkend='thread.bib.Boost'
|
||||
endterm='thread.bib.Boost.abbrev'/></citation>">
|
||||
<!ENTITY cite.Hansen73 "<citation><xref linkend='thread.bib.Hansen73'
|
||||
endterm='thread.bib.Hansen73.abbrev'/></citation>">
|
||||
<!ENTITY cite.Butenhof97 "<citation><xref linkend='thread.bib.Butenhof97'
|
||||
endterm='thread.bib.Butenhof97.abbrev'/></citation>">
|
||||
<!ENTITY cite.Hoare74 "<citation><xref linkend='thread.bib.Hoare74'
|
||||
endterm='thread.bib.Hoare74.abbrev'/></citation>">
|
||||
<!ENTITY cite.ISO98 "<citation><xref linkend='thread.bib.ISO98'
|
||||
endterm='thread.bib.ISO98.abbrev'/></citation>">
|
||||
<!ENTITY cite.McDowellHelmbold89 "<citation><xref
|
||||
linkend='thread.bib.McDowellHelmbold89'
|
||||
endterm='thread.bib.McDowellHelmbold89.abbrev'/></citation>">
|
||||
<!ENTITY cite.SchmidtPyarali "<citation><xref
|
||||
linkend='thread.bib.SchmidtPyarali'
|
||||
endterm='thread.bib.SchmidtPyarali.abbrev'/></citation>">
|
||||
<!ENTITY cite.SchmidtStalRohnertBuschmann "<citation><xref
|
||||
linkend='thread.bib.SchmidtStalRohnertBuschmann'
|
||||
endterm='thread.bib.SchmidtStalRohnertBuschmann.abbrev'/></citation>">
|
||||
<!ENTITY cite.Stroustrup "<citation><xref linkend='thread.bib.Stroustrup'
|
||||
endterm='thread.bib.Stroustrup.abbrev'/></citation>">
|
||||
@@ -1,62 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/exceptions.hpp"
|
||||
last-revision="$Date$">
|
||||
<namespace name="boost">
|
||||
<class name="lock_error">
|
||||
<purpose>
|
||||
<simpara>The lock_error class defines an exception type thrown
|
||||
to indicate a locking related error has been detected.</simpara>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<simpara>Examples of errors indicated by a lock_error exception
|
||||
include a lock operation which can be determined to result in a
|
||||
deadlock, or unlock operations attempted by a thread that does
|
||||
not own the lock.</simpara>
|
||||
</description>
|
||||
|
||||
<inherit access="public">
|
||||
<type><classname>std::logical_error</classname></type>
|
||||
</inherit>
|
||||
|
||||
<constructor>
|
||||
<effects><simpara>Constructs a <code>lock_error</code> object.
|
||||
</simpara></effects>
|
||||
</constructor>
|
||||
</class>
|
||||
|
||||
<class name="thread_resource_error">
|
||||
<purpose>
|
||||
<simpara>The <classname>thread_resource_error</classname> class
|
||||
defines an exception type that is thrown by constructors in the
|
||||
&Boost.Thread; library when thread-related resources can not be
|
||||
acquired.</simpara>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<simpara><classname>thread_resource_error</classname> is used
|
||||
only when thread-related resources cannot be acquired; memory
|
||||
allocation failures are indicated by
|
||||
<classname>std::bad_alloc</classname>.</simpara>
|
||||
</description>
|
||||
|
||||
<inherit access="public">
|
||||
<type><classname>std::runtime_error</classname></type>
|
||||
</inherit>
|
||||
|
||||
<constructor>
|
||||
<effects><simpara>Constructs a <code>thread_resource_error</code>
|
||||
object.</simpara></effects>
|
||||
</constructor>
|
||||
</class>
|
||||
</namespace>
|
||||
</header>
|
||||
592
doc/external_locking.qbk
Normal file
592
doc/external_locking.qbk
Normal file
@@ -0,0 +1,592 @@
|
||||
[/
|
||||
/ Copyright (c) 2008,2012,2014 Vicente J. Botet Escriba
|
||||
/
|
||||
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
|
||||
[section External Locking -- `strict_lock` and `externally_locked` classes]
|
||||
|
||||
|
||||
[note This tutorial is an adaptation of the paper by Andrei Alexandrescu "Multithreading and the C++ Type System"
|
||||
to the Boost library.]
|
||||
|
||||
[/
|
||||
[section Internal locking]
|
||||
|
||||
Consider, for example, modeling a bank account class that supports simultaneous deposits and withdrawals from multiple locations (arguably the "Hello, World" of multi-threaded programming). In the code below, guard's constructor locks the passed-in object this, and guard's destructor unlocks this.
|
||||
|
||||
class BankAccount {
|
||||
boost::mutex mtx_; // explicit mutex declaration
|
||||
int balance_;
|
||||
public:
|
||||
void Deposit(int amount) {
|
||||
boost::lock_guard<boost::mutex> guard(mtx_);
|
||||
balance_ += amount;
|
||||
}
|
||||
void Withdraw(int amount) {
|
||||
boost::lock_guard<boost::mutex> guard(mtx_);
|
||||
balance_ -= amount;
|
||||
}
|
||||
int GetBalance() {
|
||||
boost::lock_guard<boost::mutex> guard(mtx_);
|
||||
return balance_;
|
||||
}
|
||||
};
|
||||
|
||||
The object-level locking idiom doesn't cover the entire richness of a threading model. For example, the model above is quite deadlock-prone when you try to coordinate multi-object transactions. Nonetheless, object-level locking is useful in many cases, and in combination with other mechanisms can provide a satisfactory solution to many threaded access problems in object-oriented programs.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Internal and external locking]
|
||||
|
||||
The BankAccount class above uses internal locking. Basically, a class that uses internal locking guarantees that any concurrent calls to its public member functions don't corrupt an instance of that class. This is typically ensured by having each public member function acquire a lock on the object upon entry. This way, for any given object of that class, there can be only one member function call active at any moment, so the operations are nicely serialized.
|
||||
|
||||
This approach is reasonably easy to implement and has an attractive simplicity. Unfortunately, "simple" might sometimes morph into "simplistic."
|
||||
|
||||
Internal locking is insufficient for many real-world synchronization tasks. Imagine that you want to implement an ATM withdrawal transaction with the BankAccount class. The requirements are simple. The ATM transaction consists of two withdrawals-one for the actual money and one for the $2 commission. The two withdrawals must appear in strict sequence; that is, no other transaction can exist between them.
|
||||
|
||||
The obvious implementation is erratic:
|
||||
|
||||
void ATMWithdrawal(BankAccount& acct, int sum) {
|
||||
acct.Withdraw(sum);
|
||||
// preemption possible
|
||||
acct.Withdraw(2);
|
||||
}
|
||||
|
||||
The problem is that between the two calls above, another thread can perform another operation on the account, thus breaking the second design requirement.
|
||||
|
||||
In an attempt to solve this problem, let's lock the account from the outside during the two operations:
|
||||
|
||||
void ATMWithdrawal(BankAccount& acct, int sum) {
|
||||
boost::lock_guard<boost::mutex> guard(acct.mtx_); // mtx_ field is private
|
||||
acct.Withdraw(sum);
|
||||
acct.Withdraw(2);
|
||||
}
|
||||
|
||||
|
||||
Notice that the code above doesn't compiles, the `mtx_` field is private.
|
||||
We have two possibilities:
|
||||
|
||||
* make `mtx_` public which seams odd
|
||||
* make the `BankAccount` lockable by adding the lock/unlock functions
|
||||
|
||||
We can add these functions explicitly
|
||||
|
||||
class BankAccount {
|
||||
boost::mutex mtx_;
|
||||
int balance_;
|
||||
public:
|
||||
void Deposit(int amount) {
|
||||
boost::lock_guard<boost::mutex> guard(mtx_);
|
||||
balance_ += amount;
|
||||
}
|
||||
void Withdraw(int amount) {
|
||||
boost::lock_guard<boost::mutex> guard(mtx_);
|
||||
balance_ -= amount;
|
||||
}
|
||||
void lock() {
|
||||
mtx_.lock();
|
||||
}
|
||||
void unlock() {
|
||||
mtx_.unlock();
|
||||
}
|
||||
};
|
||||
|
||||
or inheriting from a class which add these lockable functions.
|
||||
|
||||
The `basic_lockable_adapter` class helps to define the `BankAccount` class as
|
||||
|
||||
class BankAccount
|
||||
: public basic_lockable_adapter<thread_mutex>
|
||||
{
|
||||
int balance_;
|
||||
public:
|
||||
void Deposit(int amount) {
|
||||
boost::lock_guard<BankAccount> guard(*this);
|
||||
// boost::lock_guard<boost::mutex> guard(*this->mutex());
|
||||
balance_ += amount;
|
||||
}
|
||||
void Withdraw(int amount) {
|
||||
boost::lock_guard<BankAccount> guard(*this);
|
||||
// boost::lock_guard<boost::mutex> guard(*this->mutex());
|
||||
balance_ -= amount;
|
||||
}
|
||||
int GetBalance() {
|
||||
boost::lock_guard<BankAccount> guard(*this);
|
||||
// boost::lock_guard<boost::mutex> guard(*this->mutex());
|
||||
return balance_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
and the code that does not compiles becomes
|
||||
|
||||
void ATMWithdrawal(BankAccount& acct, int sum) {
|
||||
// boost::lock_guard<boost::mutex> guard(*acct.mutex());
|
||||
boost::lock_guard<BankAccount> guard(acct);
|
||||
acct.Withdraw(sum);
|
||||
acct.Withdraw(2);
|
||||
}
|
||||
|
||||
Notice that now acct is being locked by Withdraw after it has already been locked by guard. When running such code, one of two things happens.
|
||||
|
||||
* Your mutex implementation might support the so-called recursive mutex semantics. This means that the same thread can lock the same mutex several times successfully. In this case, the implementation works but has a performance overhead due to unnecessary locking. (The locking/unlocking sequence in the two Withdraw calls is not needed but performed anyway-and that costs time.)
|
||||
* Your mutex implementation might not support recursive locking, which means that as soon as you try to acquire it the second time, it blocks-so the ATMWithdrawal function enters the dreaded deadlock.
|
||||
|
||||
As `boost::mutex` is not recursive, we need to use its recursive version `boost::recursive_mutex`.
|
||||
|
||||
class BankAccount
|
||||
: public basic_lockable_adapter<recursive_mutex>
|
||||
{
|
||||
|
||||
// ...
|
||||
};
|
||||
|
||||
The caller-ensured locking approach is more flexible and the most efficient, but very dangerous. In an implementation using caller-ensured locking, BankAccount still holds a mutex, but its member functions don't manipulate it at all. Deposit and Withdraw are not thread-safe anymore. Instead, the client code is responsible for locking BankAccount properly.
|
||||
|
||||
class BankAccount
|
||||
: public basic_lockable_adapter<boost:mutex> {
|
||||
int balance_;
|
||||
public:
|
||||
void Deposit(int amount) {
|
||||
balance_ += amount;
|
||||
}
|
||||
void Withdraw(int amount) {
|
||||
balance_ -= amount;
|
||||
}
|
||||
};
|
||||
|
||||
Obviously, the caller-ensured locking approach has a safety problem. BankAccount's implementation code is finite, and easy to reach and maintain, but there's an unbounded amount of client code that manipulates BankAccount objects. In designing applications, it's important to differentiate between requirements imposed on bounded code and unbounded code. If your class makes undue requirements on unbounded code, that's usually a sign that encapsulation is out the window.
|
||||
|
||||
To conclude, if in designing a multi-threaded class you settle on internal locking, you expose yourself to inefficiency or deadlocks. On the other hand, if you rely on caller-provided locking, you make your class error-prone and difficult to use. Finally, external locking completely avoids the issue by leaving it all to the client code.
|
||||
[endsect]
|
||||
]
|
||||
[section Locks as permits]
|
||||
|
||||
So what to do? Ideally, the BankAccount class should do the following:
|
||||
|
||||
* Support both locking models (internal and external).
|
||||
* Be efficient; that is, use no unnecessary locking.
|
||||
* Be safe; that is, BankAccount objects cannot be manipulated without appropriate locking.
|
||||
|
||||
Let's make a worthwhile observation: Whenever you lock a BankAccount, you do so by using a `lock_guard<BankAccount>` object. Turning this statement around, wherever there's a `lock_guard<BankAccount>`, there's also a locked `BankAccount` somewhere. Thus, you can think of-and use-a `lock_guard<BankAccount>` object as a permit. Owning a `lock_guard<BankAccount>` gives you rights to do certain things. The `lock_guard<BankAccount>` object should not be copied or aliased (it's not a transmissible permit).
|
||||
|
||||
# As long as a permit is still alive, the `BankAccount` object stays locked.
|
||||
# When the `lock_guard<BankAccount>` is destroyed, the `BankAccount`'s mutex is released.
|
||||
|
||||
The net effect is that at any point in your code, having access to a `lock_guard<BankAccount>` object guarantees that a `BankAccount` is locked. (You don't know exactly which `BankAccount` is locked, however-an issue that we'll address soon.)
|
||||
|
||||
For now, let's make a couple of enhancements to the `lock_guard` class template defined in Boost.Thread.
|
||||
We'll call the enhanced version `strict_lock`. Essentially, a `strict_lock`'s role is only to live on the stack as an automatic variable.
|
||||
`strict_lock` must adhere to a non-copy and non-alias policy.
|
||||
`strict_lock` disables copying by making the copy constructor and the assignment operator private.
|
||||
[/
|
||||
While we're at it, let's disable operator new and operator delete.
|
||||
|
||||
`strict_lock` are not intended to be allocated on the heap.
|
||||
`strict_lock` avoids aliasing by using a slightly less orthodox and less well-known technique: disable address taking.
|
||||
]
|
||||
|
||||
template <typename Lockable>
|
||||
class strict_lock {
|
||||
public:
|
||||
typedef Lockable lockable_type;
|
||||
|
||||
|
||||
explicit strict_lock(lockable_type& obj) : obj_(obj) {
|
||||
obj.lock(); // locks on construction
|
||||
}
|
||||
strict_lock() = delete;
|
||||
strict_lock(strict_lock const&) = delete;
|
||||
strict_lock& operator=(strict_lock const&) = delete;
|
||||
|
||||
~strict_lock() { obj_.unlock(); } // unlocks on destruction
|
||||
|
||||
bool owns_lock(mutex_type const* l) const noexcept // strict lockers specific function
|
||||
{
|
||||
return l == &obj_;
|
||||
}
|
||||
private:
|
||||
lockable_type& obj_;
|
||||
};
|
||||
|
||||
Silence can be sometimes louder than words-what's forbidden to do with a `strict_lock` is as important as what you can do. Let's see what you can and what you cannot do with a `strict_lock` instantiation:
|
||||
|
||||
* You can create a `strict_lock<T>` only starting from a valid T object. Notice that there is no other way you can create a `strict_lock<T>`.
|
||||
|
||||
BankAccount myAccount("John Doe", "123-45-6789");
|
||||
strict_lock<BankAccount> myLock(myAccount); // ok
|
||||
|
||||
* You cannot copy `strict_lock`s to one another. In particular, you cannot pass `strict_lock`s by value to functions or have them returned by functions:
|
||||
|
||||
extern strict_lock<BankAccount> Foo(); // compile-time error
|
||||
extern void Bar(strict_lock<BankAccount>); // compile-time error
|
||||
|
||||
* However, you still can pass `strict_lock`s by reference to and from functions:
|
||||
|
||||
// ok, Foo returns a reference to strict_lock<BankAccount>
|
||||
extern strict_lock<BankAccount>& Foo();
|
||||
// ok, Bar takes a reference to strict_lock<BankAccount>
|
||||
extern void Bar(strict_lock<BankAccount>&);
|
||||
|
||||
[/
|
||||
* You cannot allocate a `strict_lock` on the heap. However, you still can put `strict_lock`s on the heap if they're members of a class.
|
||||
|
||||
strict_lock<BankAccount>* pL =
|
||||
new strict_lock<BankAccount>(myAcount); //error!
|
||||
// operator new is not accessible
|
||||
class Wrapper {
|
||||
strict_lock memberLock_;
|
||||
...
|
||||
};
|
||||
Wrapper* pW = new Wrapper; // ok
|
||||
|
||||
(Making `strict_lock` a member variable of a class is not recommended. Fortunately, disabling copying and default construction makes `strict_lock` quite an unfriendly member variable.)
|
||||
|
||||
* You cannot take the address of a `strict_lock` object. This interesting feature, implemented by disabling unary operator&, makes it very unlikely to alias a `strict_lock` object. Aliasing is still possible by taking references to a `strict_lock`:
|
||||
|
||||
strict_lock<BankAccount> myLock(myAccount); // ok
|
||||
strict_lock<BankAccount>* pAlias = &myLock; // error!
|
||||
// strict_lock<BankAccount>::operator& is not accessible
|
||||
strict_lock<BankAccount>& rAlias = myLock; // ok
|
||||
|
||||
Fortunately, references don't engender as bad aliasing as pointers because they're much less versatile (references cannot be copied or reseated).
|
||||
]
|
||||
[/* You can even make `strict_lock` final; that is, impossible to derive from. This task is left in the form of an exercise to the reader.
|
||||
]
|
||||
|
||||
All these rules were put in place with one purpose-enforcing that owning a `strict_lock<T>` is a reasonably strong guarantee that
|
||||
|
||||
# you locked a T object, and
|
||||
# that object will be unlocked at a later point.
|
||||
|
||||
Now that we have such a strict `strict_lock`, how do we harness its power in defining a safe, flexible interface for BankAccount? The idea is as follows:
|
||||
|
||||
* Each of BankAccount's interface functions (in our case, Deposit and Withdraw) comes in two overloaded variants.
|
||||
* One version keeps the same signature as before, and the other takes an additional argument of type `strict_lock<BankAccount>`. The first version is internally locked; the second one requires external locking. External locking is enforced at compile time by requiring client code to create a `strict_lock<BankAccount>` object.
|
||||
* BankAccount avoids code bloating by having the internal locked functions forward to the external locked functions, which do the actual job.
|
||||
|
||||
A little code is worth 1,000 words, a (hacked into) saying goes, so here's the new BankAccount class:
|
||||
|
||||
class BankAccount
|
||||
: public basic_lockable_adapter<boost:recursive_mutex>
|
||||
{
|
||||
int balance_;
|
||||
public:
|
||||
void Deposit(int amount, strict_lock<BankAccount>&) {
|
||||
// Externally locked
|
||||
balance_ += amount;
|
||||
}
|
||||
void Deposit(int amount) {
|
||||
strict_lock<boost:mutex> guard(*this); // Internally locked
|
||||
Deposit(amount, guard);
|
||||
}
|
||||
void Withdraw(int amount, strict_lock<BankAccount>&) {
|
||||
// Externally locked
|
||||
balance_ -= amount;
|
||||
}
|
||||
void Withdraw(int amount) {
|
||||
strict_lock<boost:mutex> guard(*this); // Internally locked
|
||||
Withdraw(amount, guard);
|
||||
}
|
||||
};
|
||||
|
||||
Now, if you want the benefit of internal locking, you simply call `Deposit(int)` and `Withdraw(int)`. If you want to use external locking, you lock the object by constructing a `strict_lock<BankAccount>` and then you call `Deposit(int, strict_lock<BankAccount>&)` and `Withdraw(int, strict_lock<BankAccount>&)`. For example, here's the `ATMWithdrawal` function implemented correctly:
|
||||
|
||||
void ATMWithdrawal(BankAccount& acct, int sum) {
|
||||
strict_lock<BankAccount> guard(acct);
|
||||
acct.Withdraw(sum, guard);
|
||||
acct.Withdraw(2, guard);
|
||||
}
|
||||
|
||||
This function has the best of both worlds-it's reasonably safe and efficient at the same time.
|
||||
|
||||
It's worth noting that `strict_lock` being a template gives extra safety compared to a straight polymorphic approach. In such a design, BankAccount would derive from a Lockable interface. `strict_lock` would manipulate Lockable references so there's no need for templates. This approach is sound; however, it provides fewer compile-time guarantees. Having a `strict_lock` object would only tell that some object derived from Lockable is currently locked. In the templated approach, having a `strict_lock<BankAccount>` gives a stronger guarantee-it's a `BankAccount` that stays locked.
|
||||
|
||||
There's a weasel word in there-I mentioned that ATMWithdrawal is reasonably safe. It's not really safe because there's no enforcement that the `strict_lock<BankAccount>` object locks the appropriate BankAccount object. The type system only ensures that some BankAccount object is locked. For example, consider the following phony implementation of ATMWithdrawal:
|
||||
|
||||
void ATMWithdrawal(BankAccount& acct, int sum) {
|
||||
BankAccount fakeAcct("John Doe", "123-45-6789");
|
||||
strict_lock<BankAccount> guard(fakeAcct);
|
||||
acct.Withdraw(sum, guard);
|
||||
acct.Withdraw(2, guard);
|
||||
}
|
||||
|
||||
This code compiles warning-free but obviously doesn't do the right thing-it locks one account and uses another.
|
||||
|
||||
It's important to understand what can be enforced within the realm of the C++ type system and what needs to be enforced at runtime. The mechanism we've put in place so far ensures that some BankAccount object is locked during the call to `BankAccount::Withdraw(int, strict_lock<BankAccount>&)`. We must enforce at runtime exactly what object is locked.
|
||||
|
||||
If our scheme still needs runtime checks, how is it useful? An unwary or malicious programmer can easily lock the wrong object and manipulate any BankAccount without actually locking it.
|
||||
|
||||
First, let's get the malice issue out of the way. C is a language that requires a lot of attention and discipline from the programmer. C++ made some progress by asking a little less of those, while still fundamentally trusting the programmer. These languages are not concerned with malice (as Java is, for example). After all, you can break any C/C++ design simply by using casts "appropriately" (if appropriately is an, er, appropriate word in this context).
|
||||
|
||||
The scheme is useful because the likelihood of a programmer forgetting about any locking whatsoever is much greater than the likelihood of a programmer who does remember about locking, but locks the wrong object.
|
||||
|
||||
Using `strict_lock` permits compile-time checking of the most common source of errors, and runtime checking of the less frequent problem.
|
||||
|
||||
Let's see how to enforce that the appropriate BankAccount object is locked. First, we need to add a member function to the `strict_lock` class template.
|
||||
The `bool strict_lock<T>::owns_lock(Loclable*)` function returns a reference to the locked object.
|
||||
|
||||
template <class Lockable> class strict_lock {
|
||||
... as before ...
|
||||
public:
|
||||
bool owns_lock(Lockable* mtx) const { return mtx==&obj_; }
|
||||
};
|
||||
|
||||
Second, BankAccount needs to use this function compare the locked object against this:
|
||||
|
||||
class BankAccount {
|
||||
: public basic_lockable_adapter<boost::recursive_mutex>
|
||||
int balance_;
|
||||
public:
|
||||
void Deposit(int amount, strict_lock<BankAccount>& guard) {
|
||||
// Externally locked
|
||||
if (!guard.owns_lock(*this))
|
||||
throw "Locking Error: Wrong Object Locked";
|
||||
balance_ += amount;
|
||||
}
|
||||
// ...
|
||||
};
|
||||
|
||||
The overhead incurred by the test above is much lower than locking a recursive mutex for the second time.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Improving External Locking]
|
||||
|
||||
Now let's assume that BankAccount doesn't use its own locking at all, and has only a thread-neutral implementation:
|
||||
|
||||
class BankAccount {
|
||||
int balance_;
|
||||
public:
|
||||
void Deposit(int amount) {
|
||||
balance_ += amount;
|
||||
}
|
||||
void Withdraw(int amount) {
|
||||
balance_ -= amount;
|
||||
}
|
||||
};
|
||||
|
||||
Now you can use BankAccount in single-threaded and multi-threaded applications alike, but you need to provide your own synchronization in the latter case.
|
||||
|
||||
Say we have an AccountManager class that holds and manipulates a BankAccount object:
|
||||
|
||||
class AccountManager
|
||||
: public basic_lockable_adapter<boost::mutex>
|
||||
{
|
||||
BankAccount checkingAcct_;
|
||||
BankAccount savingsAcct_;
|
||||
...
|
||||
};
|
||||
|
||||
Let's also assume that, by design, AccountManager must stay locked while accessing its BankAccount members. The question is, how can we express this design constraint using the C++ type system? How can we state "You have access to this BankAccount object only after locking its parent AccountManager object"?
|
||||
|
||||
The solution is to use a little bridge template `externally_locked` that controls access to a BankAccount.
|
||||
|
||||
template <typename T, typename Lockable>
|
||||
class externally_locked {
|
||||
BOOST_CONCEPT_ASSERT((LockableConcept<Lockable>));
|
||||
|
||||
public:
|
||||
externally_locked(T& obj, Lockable& lockable)
|
||||
: obj_(obj)
|
||||
, lockable_(lockable)
|
||||
{}
|
||||
|
||||
externally_locked(Lockable& lockable)
|
||||
: obj_()
|
||||
, lockable_(lockable)
|
||||
{}
|
||||
|
||||
T& get(strict_lock<Lockable>& lock) {
|
||||
|
||||
#ifdef BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
|
||||
if (!lock.owns_lock(&lockable_)) throw lock_error(); run time check throw if not locks the same
|
||||
#endif
|
||||
return obj_;
|
||||
}
|
||||
void set(const T& obj, Lockable& lockable) {
|
||||
obj_ = obj;
|
||||
lockable_=lockable;
|
||||
}
|
||||
private:
|
||||
T obj_;
|
||||
Lockable& lockable_;
|
||||
};
|
||||
|
||||
`externally_locked` cloaks an object of type T, and actually provides full access to that object through the get and set member functions, provided you pass a reference to a `strict_lock<Owner>` object.
|
||||
|
||||
Instead of making `checkingAcct_` and `savingsAcct_` of type `BankAccount`, `AccountManager` holds objects of type `externally_locked<BankAccount, AccountManager>`:
|
||||
|
||||
class AccountManager
|
||||
: public basic_lockable_adapter<thread_mutex>
|
||||
{
|
||||
public:
|
||||
typedef basic_lockable_adapter<thread_mutex> lockable_base_type;
|
||||
AccountManager()
|
||||
: checkingAcct_(*this)
|
||||
, savingsAcct_(*this)
|
||||
{}
|
||||
inline void Checking2Savings(int amount);
|
||||
inline void AMoreComplicatedChecking2Savings(int amount);
|
||||
private:
|
||||
|
||||
externally_locked<BankAccount, AccountManager> checkingAcct_;
|
||||
externally_locked<BankAccount, AccountManager> savingsAcct_;
|
||||
};
|
||||
|
||||
The pattern is the same as before - to access the BankAccount object cloaked by `checkingAcct_`, you need to call `get`. To call `get`, you need to pass it a `strict_lock<AccountManager>`. The one thing you have to take care of is to not hold pointers or references you obtained by calling `get`. If you do that, make sure that you don't use them after the strict_lock has been destroyed. That is, if you alias the cloaked objects, you're back from "the compiler takes care of that" mode to "you must pay attention" mode.
|
||||
|
||||
Typically, you use `externally_locked` as shown below. Suppose you want to execute an atomic transfer from your checking account to your savings account:
|
||||
|
||||
void AccountManager::Checking2Savings(int amount) {
|
||||
strict_lock<AccountManager> guard(*this);
|
||||
checkingAcct_.get(guard).Withdraw(amount);
|
||||
savingsAcct_.get(guard).Deposit(amount);
|
||||
}
|
||||
|
||||
We achieved two important goals. First, the declaration of `checkingAcct_` and `savingsAcct_` makes it clear to the code reader that that variable is protected by a lock on an AccountManager. Second, the design makes it impossible to manipulate the two accounts without actually locking a BankAccount. `externally_locked` is what could be called active documentation.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Allowing other strict locks]
|
||||
|
||||
Now imagine that the AccountManager function needs to take a `unique_lock` in order to reduce the critical regions. And at some time it needs to access to the `checkingAcct_`. As `unique_lock` is not a strict lock the following code doesn't compile:
|
||||
|
||||
void AccountManager::AMoreComplicatedChecking2Savings(int amount) {
|
||||
unique_lock<AccountManager> guard(*this, defer_lock);
|
||||
if (some_condition()) {
|
||||
guard.lock();
|
||||
}
|
||||
checkingAcct_.get(guard).Withdraw(amount); // COMPILE ERROR
|
||||
savingsAcct_.get(guard).Deposit(amount); // COMPILE ERROR
|
||||
do_something_else();
|
||||
}
|
||||
|
||||
We need a way to transfer the ownership from the `unique_lock` to a `strict_lock` during the time we are working with `savingsAcct_` and then restore the ownership on `unique_lock`.
|
||||
|
||||
void AccountManager::AMoreComplicatedChecking2Savings(int amount) {
|
||||
unique_lock<AccountManager> guard1(*this, defer_lock);
|
||||
if (some_condition()) {
|
||||
guard1.lock();
|
||||
}
|
||||
{
|
||||
strict_lock<AccountManager> guard(guard1);
|
||||
checkingAcct_.get(guard).Withdraw(amount);
|
||||
savingsAcct_.get(guard).Deposit(amount);
|
||||
}
|
||||
guard1.unlock();
|
||||
}
|
||||
|
||||
In order to make this code compilable we need to store either a Lockable or a `unique_lock<Lockable>` reference depending on the constructor. We also need to store which kind of reference we have stored, and in the destructor call either to the Lockable `unlock` or restore the ownership.
|
||||
|
||||
This seems too complicated to me. Another possibility is to define a nested strict lock class. The drawback is that instead of having only one strict lock we have two and we need either to duplicate every function taking a `strict_lock` or make these function templates. The problem with template functions is that we don't profit anymore of the C++ type system. We must add some static metafunction that checks that the Locker parameter is a strict lock. The problem is that we can not really check this or can we?. The `is_strict_lock` metafunction must be specialized by the strict lock developer. We need to believe it "sur parole". The advantage is that now we can manage with more than two strict locks without changing our code. This is really nice.
|
||||
|
||||
Now we need to state that both classes are `strict_lock`s.
|
||||
|
||||
template <typename Locker>
|
||||
struct is_strict_lock : mpl::false_ {};
|
||||
|
||||
template <typename Lockable>
|
||||
struct is_strict_lock<strict_lock<Lockable> > : mpl::true_ {}
|
||||
|
||||
template <typename Locker>
|
||||
struct is_strict_lock<nested_strict_lock<Locker> > : mpl::true_ {}
|
||||
|
||||
|
||||
Well let me show what this `nested_strict_lock` class looks like and the impacts on the `externally_locked` class and the `AccountManager::AMoreComplicatedFunction` function.
|
||||
|
||||
First `nested_strict_lock` class will store on a temporary lock the `Locker`, and transfer the lock ownership on the constructor. On destruction it will restore the ownership. Note the use of `lock_traits` and that the `Locker` needs to have a reference to the mutex otherwise and exception is thrown.
|
||||
|
||||
template <typename Locker >
|
||||
class nested_strict_lock
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT((MovableLockerConcept<Locker>));
|
||||
public:
|
||||
typedef typename lockable_type<Locker>::type lockable_type;
|
||||
typedef typename syntactic_lock_traits<lockable_type>::lock_error lock_error;
|
||||
|
||||
nested_strict_lock(Locker& lock)
|
||||
: lock_(lock) // Store reference to locker
|
||||
, tmp_lock_(lock.move()) // Move ownership to temporaty locker
|
||||
{
|
||||
#ifdef BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
|
||||
if (tmp_lock_.mutex()==0) {
|
||||
lock_=tmp_lock_.move(); // Rollback for coherency purposes
|
||||
throw lock_error();
|
||||
}
|
||||
#endif
|
||||
if (!tmp_lock_) tmp_lock_.lock(); // ensures it is locked
|
||||
}
|
||||
~nested_strict_lock() {
|
||||
lock_=tmp_lock_.move(); // Move ownership to nesting locker
|
||||
}
|
||||
bool owns_lock() const { return true; }
|
||||
lockable_type* mutex() const { return tmp_lock_.mutex(); }
|
||||
bool owns_lock(lockable_type* l) const { return l==mutex(); }
|
||||
|
||||
|
||||
private:
|
||||
Locker& lock_;
|
||||
Locker tmp_lock_;
|
||||
};
|
||||
|
||||
[/
|
||||
typedef bool (nested_strict_lock::*bool_type)() const;
|
||||
operator bool_type() const { return &nested_strict_lock::owns_lock; }
|
||||
bool operator!() const { return false; }
|
||||
|
||||
BOOST_ADRESS_OF_DELETE(nested_strict_lock)
|
||||
BOOST_HEAP_ALLOCATEION_DELETE(nested_strict_lock)
|
||||
BOOST_DEFAULT_CONSTRUCTOR_DELETE(nested_strict_lock)
|
||||
BOOST_COPY_CONSTRUCTOR_DELETE(nested_strict_lock)
|
||||
BOOST_COPY_ASSIGNEMENT_DELETE(nested_strict_lock)
|
||||
|
||||
]
|
||||
|
||||
The `externally_locked` get function is now a template function taking a Locker as parameters instead of a `strict_lock`.
|
||||
We can add test in debug mode that ensure that the Lockable object is locked.
|
||||
|
||||
template <typename T, typename Lockable>
|
||||
class externally_locked {
|
||||
public:
|
||||
// ...
|
||||
template <class Locker>
|
||||
T& get(Locker& lock) {
|
||||
BOOST_CONCEPT_ASSERT((StrictLockerConcept<Locker>));
|
||||
|
||||
BOOST_STATIC_ASSERT((is_strict_lock<Locker>::value)); // locker is a strict locker "sur parole"
|
||||
BOOST_STATIC_ASSERT((is_same<Lockable,
|
||||
typename lockable_type<Locker>::type>::value)); // that locks the same type
|
||||
#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_OWNERSHIP // define BOOST_THREAD_EXTERNALLY_LOCKED_NO_CHECK_OWNERSHIP if you don't want to check locker ownership
|
||||
if (! lock ) throw lock_error(); // run time check throw if no locked
|
||||
#endif
|
||||
#ifdef BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
|
||||
if (!lock.owns_lock(&lockable_)) throw lock_error();
|
||||
#endif
|
||||
return obj_;
|
||||
}
|
||||
};
|
||||
|
||||
The `AccountManager::AMoreComplicatedFunction` function needs only to replace the `strict_lock` by a `nested_strict_lock`.
|
||||
|
||||
void AccountManager::AMoreComplicatedChecking2Savings(int amount) {
|
||||
unique_lock<AccountManager> guard1(*this);
|
||||
if (some_condition()) {
|
||||
guard1.lock();
|
||||
}
|
||||
{
|
||||
nested_strict_lock<unique_lock<AccountManager> > guard(guard1);
|
||||
checkingAcct_.get(guard).Withdraw(amount);
|
||||
savingsAcct_.get(guard).Deposit(amount);
|
||||
}
|
||||
guard1.unlock();
|
||||
}
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
235
doc/faq.xml
235
doc/faq.xml
@@ -1,235 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.faq" last-revision="$Date$">
|
||||
<title>Frequently Asked Questions</title>
|
||||
<qandaset>
|
||||
<qandaentry>
|
||||
<question>
|
||||
<para>Are lock objects <link
|
||||
linkend="thread.glossary.thread-safe">thread safe</link>?</para>
|
||||
</question>
|
||||
<answer>
|
||||
<para><emphasis role="bold">No!</emphasis> Lock objects are not meant to
|
||||
be shared between threads. They are meant to be short-lived objects
|
||||
created on automatic storage within a code block. Any other usage is
|
||||
just likely to lead to errors and won't really be of actual benefit anyway.
|
||||
Share <link linkend="thread.concepts.mutexes">Mutexes</link>, not
|
||||
Locks. For more information see the <link
|
||||
linkend="thread.rationale.locks">rationale</link> behind the
|
||||
design for lock objects.</para>
|
||||
</answer>
|
||||
</qandaentry>
|
||||
<qandaentry>
|
||||
<question>
|
||||
<para>Why was &Boost.Thread; modeled after (specific library
|
||||
name)?</para>
|
||||
</question>
|
||||
<answer>
|
||||
<para>It wasn't. &Boost.Thread; was designed from scratch. Extensive
|
||||
design discussions involved numerous people representing a wide range of
|
||||
experience across many platforms. To ensure portability, the initial
|
||||
implements were done in parallel using POSIX Threads and the Win32
|
||||
threading API. But the &Boost.Thread; design is very much in the spirit
|
||||
of C++, and thus doesn't model such C based APIs.</para>
|
||||
</answer>
|
||||
</qandaentry>
|
||||
<qandaentry>
|
||||
<question>
|
||||
<para>Why wasn't &Boost.Thread; modeled after (specific library
|
||||
name)?</para>
|
||||
</question>
|
||||
<answer>
|
||||
<para>Existing C++ libraries either seemed dangerous (often failing to
|
||||
take advantage of prior art to reduce errors) or had excessive
|
||||
dependencies on library components unrelated to threading. Existing C
|
||||
libraries couldn't meet our C++ requirements, and were also missing
|
||||
certain features. For instance, the WIN32 thread API lacks condition
|
||||
variables, even though these are critical for the important Monitor
|
||||
pattern &cite.SchmidtStalRohnertBuschmann;.</para>
|
||||
</answer>
|
||||
</qandaentry>
|
||||
<qandaentry>
|
||||
<question>
|
||||
<para>Why do <link linkend="thread.concepts.mutexes">Mutexes</link>
|
||||
have noncopyable semantics?</para>
|
||||
</question>
|
||||
<answer>
|
||||
<para>To ensure that <link
|
||||
linkend="thread.glossary.deadlock">deadlocks</link> don't occur. The
|
||||
only logical form of copy would be to use some sort of shallow copy
|
||||
semantics in which multiple mutex objects could refer to the same mutex
|
||||
state. This means that if ObjA has a mutex object as part of its state
|
||||
and ObjB is copy constructed from it, then when ObjB::foo() locks the
|
||||
mutex it has effectively locked ObjA as well. This behavior can result
|
||||
in deadlock. Other copy semantics result in similar problems (if you
|
||||
think you can prove this to be wrong then supply us with an alternative
|
||||
and we'll reconsider).</para>
|
||||
</answer>
|
||||
</qandaentry>
|
||||
<qandaentry>
|
||||
<question>
|
||||
<para>How can you prevent <link
|
||||
linkend="thread.glossary.deadlock">deadlock</link> from occurring when
|
||||
a thread must lock multiple mutexes?</para>
|
||||
</question>
|
||||
<answer>
|
||||
<para>Always lock them in the same order. One easy way of doing this is
|
||||
to use each mutex's address to determine the order in which they are
|
||||
locked. A future &Boost.Thread; concept may wrap this pattern up in a
|
||||
reusable class.</para>
|
||||
</answer>
|
||||
</qandaentry>
|
||||
<qandaentry>
|
||||
<question>
|
||||
<para>Don't noncopyable <link
|
||||
linkend="thread.concepts.mutexes">Mutex</link> semantics mean that a
|
||||
class with a mutex member will be noncopyable as well?</para>
|
||||
</question>
|
||||
<answer>
|
||||
<para>No, but what it does mean is that the compiler can't generate a
|
||||
copy constructor and assignment operator, so they will have to be coded
|
||||
explicitly. This is a <emphasis role="bold">good thing</emphasis>,
|
||||
however, since the compiler generated operations would not be <link
|
||||
linkend="thread.glossary.thread-safe">thread-safe</link>. The following
|
||||
is a simple example of a class with copyable semantics and internal
|
||||
synchronization through a mutex member.</para>
|
||||
<programlisting>
|
||||
class counter
|
||||
{
|
||||
public:
|
||||
// Doesn't need synchronization since there can be no references to *this
|
||||
// until after it's constructed!
|
||||
explicit counter(int initial_value)
|
||||
: m_value(initial_value)
|
||||
{
|
||||
}
|
||||
// We only need to synchronize other for the same reason we don't have to
|
||||
// synchronize on construction!
|
||||
counter(const counter& other)
|
||||
{
|
||||
boost::mutex::scoped_lock scoped_lock(other.m_mutex);
|
||||
m_value = other.m_value;
|
||||
}
|
||||
// For assignment we need to synchronize both objects!
|
||||
const counter& operator=(const counter& other)
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
boost::mutex::scoped_lock lock1(&m_mutex < &other.m_mutex ? m_mutex : other.m_mutex);
|
||||
boost::mutex::scoped_lock lock2(&m_mutex > &other.m_mutex ? m_mutex : other.m_mutex);
|
||||
m_value = other.m_value;
|
||||
return *this;
|
||||
}
|
||||
int value() const
|
||||
{
|
||||
boost::mutex::scoped_lock scoped_lock(m_mutex);
|
||||
return m_value;
|
||||
}
|
||||
int increment()
|
||||
{
|
||||
boost::mutex::scoped_lock scoped_lock(m_mutex);
|
||||
return ++m_value;
|
||||
}
|
||||
private:
|
||||
mutable boost::mutex m_mutex;
|
||||
int m_value;
|
||||
};
|
||||
</programlisting>
|
||||
</answer>
|
||||
</qandaentry>
|
||||
<qandaentry>
|
||||
<question>
|
||||
<para>How can you lock a <link
|
||||
linkend="thread.concepts.mutexes">Mutex</link> member in a const member
|
||||
function, in order to implement the Monitor Pattern?</para>
|
||||
</question>
|
||||
<answer>
|
||||
<para>The Monitor Pattern &cite.SchmidtStalRohnertBuschmann; mutex
|
||||
should simply be declared as mutable. See the example code above. The
|
||||
internal state of mutex types could have been made mutable, with all
|
||||
lock calls made via const functions, but this does a poor job of
|
||||
documenting the actual semantics (and in fact would be incorrect since
|
||||
the logical state of a locked mutex clearly differs from the logical
|
||||
state of an unlocked mutex). Declaring a mutex member as mutable clearly
|
||||
documents the intended semantics.</para>
|
||||
</answer>
|
||||
</qandaentry>
|
||||
<qandaentry>
|
||||
<question>
|
||||
<para>Why supply <classname>boost::condition</classname> variables rather than
|
||||
event variables?</para>
|
||||
</question>
|
||||
<answer>
|
||||
<para>Condition variables result in user code much less prone to <link
|
||||
linkend="thread.glossary.race-condition">race conditions</link> than
|
||||
event variables. See <xref linkend="thread.rationale.events" />
|
||||
for analysis. Also see &cite.Hoare74; and &cite.SchmidtStalRohnertBuschmann;.
|
||||
</para>
|
||||
</answer>
|
||||
</qandaentry>
|
||||
<qandaentry>
|
||||
<question>
|
||||
<para>Why isn't thread cancellation or termination provided?</para>
|
||||
</question>
|
||||
<answer>
|
||||
<para>There's a valid need for thread termination, so at some point
|
||||
&Boost.Thread; probably will include it, but only after we can find a
|
||||
truly safe (and portable) mechanism for this concept.</para>
|
||||
</answer>
|
||||
</qandaentry>
|
||||
<qandaentry>
|
||||
<question>
|
||||
<para>Is it safe for threads to share automatic storage duration (stack)
|
||||
objects via pointers or references?</para>
|
||||
</question>
|
||||
<answer>
|
||||
<para>Only if you can guarantee that the lifetime of the stack object
|
||||
will not end while other threads might still access the object. Thus the
|
||||
safest practice is to avoid sharing stack objects, particularly in
|
||||
designs where threads are created and destroyed dynamically. Restrict
|
||||
sharing of stack objects to simple designs with very clear and
|
||||
unchanging function and thread lifetimes. (Suggested by Darryl
|
||||
Green).</para>
|
||||
</answer>
|
||||
</qandaentry>
|
||||
<qandaentry>
|
||||
<question>
|
||||
<para>Why has class semaphore disappeared?</para>
|
||||
</question>
|
||||
<answer>
|
||||
<para>Semaphore was removed as too error prone. The same effect can be
|
||||
achieved with greater safety by the combination of a mutex and a
|
||||
condition variable.</para>
|
||||
</answer>
|
||||
</qandaentry>
|
||||
<qandaentry>
|
||||
<question>
|
||||
<para>Why doesn't the thread's ctor take at least a void* to pass any
|
||||
information along with the function? All other threading libs support
|
||||
that and it makes Boost.Threads inferiour. </para>
|
||||
</question>
|
||||
<answer>
|
||||
<para>There is no need, because Boost.Threads are superiour! First
|
||||
thing is that its ctor doesn't take a function but a functor. That
|
||||
means that you can pass an object with an overloaded operator() and
|
||||
include additional data as members in that object. Beware though that
|
||||
this object is copied, use boost::ref to prevent that. Secondly, even
|
||||
a boost::function<void (void)> can carry parameters, you only have to
|
||||
use boost::bind() to create it from any function and bind its
|
||||
parameters.</para>
|
||||
<para>That is also why Boost.Threads are superiour, because they
|
||||
don't require you to pass a type-unsafe void pointer. Rather, you can
|
||||
use the flexible Boost.Functions to create a thread entry out of
|
||||
anything that can be called.</para>
|
||||
</answer>
|
||||
</qandaentry>
|
||||
</qandaset>
|
||||
</section>
|
||||
2500
doc/future_ref.qbk
Normal file
2500
doc/future_ref.qbk
Normal file
File diff suppressed because it is too large
Load Diff
463
doc/futures.qbk
Executable file
463
doc/futures.qbk
Executable file
@@ -0,0 +1,463 @@
|
||||
[/
|
||||
(C) Copyright 2008-11 Anthony Williams.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:futures Futures]
|
||||
|
||||
[template future_state_link[link_text] [link thread.synchronization.futures.reference.future_state [link_text]]]
|
||||
[def __uninitialized__ [future_state_link `boost::future_state::uninitialized`]]
|
||||
[def __ready__ [future_state_link `boost::future_state::ready`]]
|
||||
[def __waiting__ [future_state_link `boost::future_state::waiting`]]
|
||||
|
||||
[def __future_uninitialized__ `boost::future_uninitialized`]
|
||||
[def __broken_promise__ `boost::broken_promise`]
|
||||
[def __future_already_retrieved__ `boost::future_already_retrieved`]
|
||||
[def __task_moved__ `boost::task_moved`]
|
||||
[def __task_already_started__ `boost::task_already_started`]
|
||||
[def __promise_already_satisfied__ `boost::promise_already_satisfied`]
|
||||
|
||||
[def __thread_interrupted__ `boost::thread_interrupted`]
|
||||
|
||||
|
||||
[template unique_future_link[link_text] [link thread.synchronization.futures.reference.unique_future [link_text]]]
|
||||
[def __unique_future__ [unique_future_link `future`]]
|
||||
[def __unique_future `future`]
|
||||
|
||||
[template unique_future_get_link[link_text] [link thread.synchronization.futures.reference.unique_future.get [link_text]]]
|
||||
[def __unique_future_get__ [unique_future_get_link `boost::future<R>::get()`]]
|
||||
|
||||
[template unique_future_wait_link[link_text] [link thread.synchronization.futures.reference.unique_future.wait [link_text]]]
|
||||
[def __unique_future_wait__ [unique_future_wait_link `boost::future<R>::wait()`]]
|
||||
|
||||
[template unique_future_is_ready_link[link_text] [link thread.synchronization.futures.reference.unique_future.is_ready [link_text]]]
|
||||
[def __unique_future_is_ready__ [unique_future_is_ready_link `boost::future<R>::is_ready()`]]
|
||||
|
||||
[template unique_future_has_value_link[link_text] [link thread.synchronization.futures.reference.unique_future.has_value [link_text]]]
|
||||
[def __unique_future_has_value__ [unique_future_has_value_link `boost::future<R>::has_value()`]]
|
||||
|
||||
[template unique_future_has_exception_link[link_text] [link thread.synchronization.futures.reference.unique_future.has_exception [link_text]]]
|
||||
[def __unique_future_has_exception__ [unique_future_has_exception_link `boost::future<R>::has_exception()`]]
|
||||
|
||||
[template unique_future_get_state_link[link_text] [link thread.synchronization.futures.reference.unique_future.get_state [link_text]]]
|
||||
[def __unique_future_get_state__ [unique_future_get_state_link `boost::future<R>::get_state()`]]
|
||||
|
||||
[template shared_future_link[link_text] [link thread.synchronization.futures.reference.shared_future [link_text]]]
|
||||
[def __shared_future__ [shared_future_link `boost::shared_future`]]
|
||||
|
||||
[template shared_future_get_link[link_text] [link thread.synchronization.futures.reference.shared_future.get [link_text]]]
|
||||
[def __shared_future_get__ [shared_future_get_link `boost::shared_future<R>::get()`]]
|
||||
|
||||
[template shared_future_wait_link[link_text] [link thread.synchronization.futures.reference.shared_future.wait [link_text]]]
|
||||
[def __shared_future_wait__ [shared_future_wait_link `boost::shared_future<R>::wait()`]]
|
||||
|
||||
[template shared_future_is_ready_link[link_text] [link thread.synchronization.futures.reference.shared_future.is_ready [link_text]]]
|
||||
[def __shared_future_is_ready__ [shared_future_is_ready_link `boost::shared_future<R>::is_ready()`]]
|
||||
|
||||
[template shared_future_has_value_link[link_text] [link thread.synchronization.futures.reference.shared_future.has_value [link_text]]]
|
||||
[def __shared_future_has_value__ [shared_future_has_value_link `boost::shared_future<R>::has_value()`]]
|
||||
|
||||
[template shared_future_has_exception_link[link_text] [link thread.synchronization.futures.reference.shared_future.has_exception [link_text]]]
|
||||
[def __shared_future_has_exception__ [shared_future_has_exception_link `boost::shared_future<R>::has_exception()`]]
|
||||
|
||||
[template shared_future_get_state_link[link_text] [link thread.synchronization.futures.reference.shared_future.get_state [link_text]]]
|
||||
[def __shared_future_get_state__ [shared_future_get_state_link `boost::shared_future<R>::get_state()`]]
|
||||
|
||||
[template promise_link[link_text] [link thread.synchronization.futures.reference.promise [link_text]]]
|
||||
[def __promise__ [promise_link `boost::promise`]]
|
||||
|
||||
[template packaged_task_link[link_text] [link thread.synchronization.futures.reference.packaged_task [link_text]]]
|
||||
[def __packaged_task__ [packaged_task_link `boost::packaged_task`]]
|
||||
[def __packaged_task [packaged_task_link `boost::packaged_task`]]
|
||||
|
||||
[template wait_for_any_link[link_text] [link thread.synchronization.futures.reference.wait_for_any [link_text]]]
|
||||
[def __wait_for_any__ [wait_for_any_link `boost::wait_for_any()`]]
|
||||
|
||||
[template wait_for_all_link[link_text] [link thread.synchronization.futures.reference.wait_for_all [link_text]]]
|
||||
[def __wait_for_all__ [wait_for_all_link `boost::wait_for_all()`]]
|
||||
|
||||
|
||||
[section:overview Overview]
|
||||
|
||||
The futures library provides a means of handling synchronous future values, whether those values are generated by another thread, or
|
||||
on a single thread in response to external stimuli, or on-demand.
|
||||
|
||||
This is done through the provision of four class templates: __unique_future__ and __shared_future__ which are used to retrieve the
|
||||
asynchronous results, and __promise__ and __packaged_task__ which are used to generate the asynchronous results.
|
||||
|
||||
An instance of __unique_future__ holds the one and only reference to a result. Ownership can be transferred between instances using
|
||||
the move constructor or move-assignment operator, but at most one instance holds a reference to a given asynchronous result. When
|
||||
the result is ready, it is returned from __unique_future_get__ by rvalue-reference to allow the result to be moved or copied as
|
||||
appropriate for the type.
|
||||
|
||||
On the other hand, many instances of __shared_future__ may reference the same result. Instances can be freely copied and assigned,
|
||||
and __shared_future_get__ returns a non `const` reference so that multiple calls to __shared_future_get__ are safe. You can move an
|
||||
instance of __unique_future__ into an instance of __shared_future__, thus transferring ownership of the associated asynchronous
|
||||
result, but not vice-versa.
|
||||
|
||||
`boost::async` is a simple way of running asynchronous tasks. A call to `boost::async` returns a __unique_future__ that will contain the result of the task.
|
||||
|
||||
|
||||
You can wait for futures either individually or with one of the __wait_for_any__ and __wait_for_all__ functions.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:creating Creating asynchronous values]
|
||||
|
||||
You can set the value in a future with either a __promise__ or a __packaged_task__. A __packaged_task__ is a callable object that
|
||||
wraps a function or callable object. When the packaged task is invoked, it invokes the contained function in turn, and populates a
|
||||
future with the return value. This is an answer to the perennial question: "how do I return a value from a thread?": package the
|
||||
function you wish to run as a __packaged_task__ and pass the packaged task to the thread constructor. The future retrieved from the
|
||||
packaged task can then be used to obtain the return value. If the function throws an exception, that is stored in the future in
|
||||
place of the return value.
|
||||
|
||||
int calculate_the_answer_to_life_the_universe_and_everything()
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
|
||||
boost::packaged_task<int> pt(calculate_the_answer_to_life_the_universe_and_everything);
|
||||
boost::__unique_future__<int> fi=pt.get_future();
|
||||
|
||||
boost::thread task(boost::move(pt)); // launch task on a thread
|
||||
|
||||
fi.wait(); // wait for it to finish
|
||||
|
||||
assert(fi.is_ready());
|
||||
assert(fi.has_value());
|
||||
assert(!fi.has_exception());
|
||||
assert(fi.get_state()==boost::future_state::ready);
|
||||
assert(fi.get()==42);
|
||||
|
||||
|
||||
A __promise__ is a bit more low level: it just provides explicit functions to store a value or an exception in the associated
|
||||
future. A promise can therefore be used where the value may come from more than one possible source, or where a single operation may
|
||||
produce multiple values.
|
||||
|
||||
boost::promise<int> pi;
|
||||
boost::__unique_future__<int> fi;
|
||||
fi=pi.get_future();
|
||||
|
||||
pi.set_value(42);
|
||||
|
||||
assert(fi.is_ready());
|
||||
assert(fi.has_value());
|
||||
assert(!fi.has_exception());
|
||||
assert(fi.get_state()==boost::future_state::ready);
|
||||
assert(fi.get()==42);
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:lazy_futures Wait Callbacks and Lazy Futures]
|
||||
|
||||
Both __promise__ and __packaged_task__ support ['wait callbacks] that are invoked when a thread blocks in a call to `wait()` or
|
||||
`timed_wait()` on a future that is waiting for the result from the __promise__ or __packaged_task__, in the thread that is doing the
|
||||
waiting. These can be set using the `set_wait_callback()` member function on the __promise__ or __packaged_task__ in question.
|
||||
|
||||
This allows ['lazy futures] where the result is not actually computed until it is needed by some thread. In the example below, the
|
||||
call to `f.get()` invokes the callback `invoke_lazy_task`, which runs the task to set the value. If you remove the call to
|
||||
`f.get()`, the task is not ever run.
|
||||
|
||||
int calculate_the_answer_to_life_the_universe_and_everything()
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
|
||||
void invoke_lazy_task(boost::packaged_task<int>& task)
|
||||
{
|
||||
try
|
||||
{
|
||||
task();
|
||||
}
|
||||
catch(boost::task_already_started&)
|
||||
{}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::packaged_task<int> task(calculate_the_answer_to_life_the_universe_and_everything);
|
||||
task.set_wait_callback(invoke_lazy_task);
|
||||
boost::__unique_future__<int> f(task.get_future());
|
||||
|
||||
assert(f.get()==42);
|
||||
}
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:at_thread_exit Handling Detached Threads and Thread Specific Variables]
|
||||
|
||||
Detached threads pose a problem for objects with thread storage duration.
|
||||
If we use a mechanism other than `thread::__join` to wait for a __thread to complete its work - such as waiting for a future to be ready -
|
||||
then the destructors of thread specific variables will still be running after the waiting thread has resumed.
|
||||
This section explain how the standard mechanism can be used to make such synchronization safe by ensuring that the
|
||||
objects with thread storage duration are destroyed prior to the future being made ready. e.g.
|
||||
|
||||
int find_the_answer(); // uses thread specific objects
|
||||
void thread_func(boost::promise<int>&& p)
|
||||
{
|
||||
p.set_value_at_thread_exit(find_the_answer());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::promise<int> p;
|
||||
boost::thread t(thread_func,boost::move(p));
|
||||
t.detach(); // we're going to wait on the future
|
||||
std::cout<<p.get_future().get()<<std::endl;
|
||||
}
|
||||
|
||||
When the call to `get()` returns, we know that not only is the future value ready, but the thread specific variables
|
||||
on the other thread have also been destroyed.
|
||||
|
||||
Such mechanisms are provided for `boost::condition_variable`, `boost::promise` and `boost::packaged_task`. e.g.
|
||||
|
||||
void task_executor(boost::packaged_task<void(int)> task,int param)
|
||||
{
|
||||
task.make_ready_at_thread_exit(param); // execute stored task
|
||||
} // destroy thread specific and wake threads waiting on futures from task
|
||||
|
||||
Other threads can wait on a future obtained from the task without having to worry about races due to the execution of
|
||||
destructors of the thread specific objects from the task's thread.
|
||||
|
||||
boost::condition_variable cv;
|
||||
boost::mutex m;
|
||||
complex_type the_data;
|
||||
bool data_ready;
|
||||
|
||||
void thread_func()
|
||||
{
|
||||
boost::unique_lock<std::mutex> lk(m);
|
||||
the_data=find_the_answer();
|
||||
data_ready=true;
|
||||
boost::notify_all_at_thread_exit(cv,boost::move(lk));
|
||||
} // destroy thread specific objects, notify cv, unlock mutex
|
||||
|
||||
void waiting_thread()
|
||||
{
|
||||
boost::unique_lock<std::mutex> lk(m);
|
||||
while(!data_ready)
|
||||
{
|
||||
cv.wait(lk);
|
||||
}
|
||||
process(the_data);
|
||||
}
|
||||
|
||||
The waiting thread is guaranteed that the thread specific objects used by `thread_func()` have been destroyed by the time
|
||||
`process(the_data)` is called. If the lock on `m` is released and re-acquired after setting `data_ready` and before calling
|
||||
`boost::notify_all_at_thread_exit()` then this does NOT hold, since the thread may return from the wait due to a
|
||||
spurious wake-up.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:async Executing asynchronously]
|
||||
|
||||
`boost::async` is a simple way of running asynchronous tasks to make use of the available hardware concurrency.
|
||||
A call to `boost::async` returns a `boost::future` that will contain the result of the task. Depending on
|
||||
the launch policy, the task is either run asynchronously on its own thread or synchronously on whichever thread
|
||||
calls the `wait()` or `get()` member functions on that `future`.
|
||||
|
||||
A launch policy of either boost::launch::async, which asks the runtime to create an asynchronous thread,
|
||||
or boost::launch::deferred, which indicates you simply want to defer the function call until a later time (lazy evaluation).
|
||||
This argument is optional - if you omit it your function will use the default policy.
|
||||
|
||||
For example, consider computing the sum of a very large array. The first task is to not compute asynchronously when
|
||||
the overhead would be significant. The second task is to split the work into two pieces, one executed by the host
|
||||
thread and one executed asynchronously.
|
||||
|
||||
|
||||
int parallel_sum(int* data, int size)
|
||||
{
|
||||
int sum = 0;
|
||||
if ( size < 1000 )
|
||||
for ( int i = 0; i < size; ++i )
|
||||
sum += data[i];
|
||||
else {
|
||||
auto handle = boost::async(parallel_sum, data+size/2, size-size/2);
|
||||
sum += parallel_sum(data, size/2);
|
||||
sum += handle.get();
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:shared Shared Futures]
|
||||
|
||||
`shared_future` is designed to be shared between threads,
|
||||
that is to allow multiple concurrent get operations.
|
||||
|
||||
[heading Multiple get]
|
||||
|
||||
The second `get()` call in the following example is undefined.
|
||||
|
||||
void bad_second_use( type arg ) {
|
||||
|
||||
auto ftr = async( [=]{ return work( arg ); } );
|
||||
if ( cond1 )
|
||||
{
|
||||
use1( ftr.get() );
|
||||
} else
|
||||
{
|
||||
use2( ftr.get() );
|
||||
}
|
||||
use3( ftr.get() ); // second use is undefined
|
||||
}
|
||||
|
||||
Using a `shared_future` solves the issue
|
||||
|
||||
void good_second_use( type arg ) {
|
||||
|
||||
shared_future<type> ftr = async( [=]{ return work( arg ); } );
|
||||
if ( cond1 )
|
||||
{
|
||||
use1( ftr.get() );
|
||||
} else
|
||||
{
|
||||
use2( ftr.get() );
|
||||
}
|
||||
use3( ftr.get() ); // second use is defined
|
||||
}
|
||||
|
||||
[heading share()]
|
||||
|
||||
Namming the return type when declaring the `shared_future` is needed; auto is not available within template argument lists.
|
||||
Here `share()` could be used to simplify the code
|
||||
|
||||
void better_second_use( type arg ) {
|
||||
|
||||
auto ftr = async( [=]{ return work( arg ); } ).share();
|
||||
if ( cond1 )
|
||||
{
|
||||
use1( ftr.get() );
|
||||
} else
|
||||
{
|
||||
use2( ftr.get() );
|
||||
}
|
||||
use3( ftr.get() ); // second use is defined
|
||||
}
|
||||
|
||||
[heading Writing on get()]
|
||||
|
||||
The user can either read or write the future avariable.
|
||||
|
||||
void write_to_get( type arg ) {
|
||||
|
||||
auto ftr = async( [=]{ return work( arg ); } ).share();
|
||||
if ( cond1 )
|
||||
{
|
||||
use1( ftr.get() );
|
||||
} else
|
||||
{
|
||||
if ( cond2 )
|
||||
use2( ftr.get() );
|
||||
else
|
||||
ftr.get() = something(); // assign to non-const reference.
|
||||
}
|
||||
use3( ftr.get() ); // second use is defined
|
||||
}
|
||||
|
||||
This works because the `shared_future<>::get()` function returns a non-const reference to the appropriate storage.
|
||||
Of course the access to this storage must be ensured by the user. The library doesn't ensure the access to the internal storage is thread safe.
|
||||
|
||||
There has been some work by the C++ standard committe on an `atomic_future` that behaves as an `atomic` variable, that is is thread_safe,
|
||||
and a `shared_future` that can be shared between several threads, but there were not enough consensus and time to get it ready for C++11.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:make_ready_future Making immediate futures easier]
|
||||
|
||||
Some functions may know the value at the point of construction. In these cases the value is immediately available,
|
||||
but needs to be returned as a future or shared_future. By using make_ready_future a future
|
||||
can be created which holds a pre-computed result in its shared state.
|
||||
|
||||
Without these features it is non-trivial to create a future directly from a value.
|
||||
First a promise must be created, then the promise is set, and lastly the future is retrieved from the promise.
|
||||
This can now be done with one operation.
|
||||
|
||||
[heading make_ready_future]
|
||||
|
||||
This function creates a future for a given value. If no value is given then a future<void> is returned.
|
||||
This function is primarily useful in cases where sometimes, the return value is immediately available, but sometimes
|
||||
it is not. The example below illustrates, that in an error path the value is known immediately, however in other paths
|
||||
the function must return an eventual value represented as a future.
|
||||
|
||||
|
||||
boost::future<int> compute(int x)
|
||||
{
|
||||
if (x == 0) return boost::make_ready_future(0);
|
||||
if (x < 0) return boost::make_ready_future<int>(std::logic_error("Error"));
|
||||
boost::future<int> f1 = boost::async([]() { return x+1; });
|
||||
return f1;
|
||||
}
|
||||
|
||||
There are two variations of this function. The first takes a value of any type, and returns a future of that type.
|
||||
The input value is passed to the shared state of the returned future. The second version takes no input and returns a future<void>.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:then Associating future continuations]
|
||||
|
||||
In asynchronous programming, it is very common for one asynchronous operation, on completion, to invoke a second
|
||||
operation and pass data to it. The current C++ standard does not allow one to register a continuation to a future.
|
||||
With `.then`, instead of waiting for the result, a continuation is "attached" to the asynchronous operation, which is
|
||||
invoked when the result is ready. Continuations registered using the `.then` function will help to avoid blocking waits
|
||||
or wasting threads on polling, greatly improving the responsiveness and scalability of an application.
|
||||
|
||||
`future.then()` provides the ability to sequentially compose two futures by declaring one to be the continuation of another.
|
||||
With `.then()` the antecedent future is ready (has a value or exception stored in the shared state) before the continuation
|
||||
starts as instructed by the lambda function.
|
||||
|
||||
In the example below the `future<string>` `f2` is registered to be a continuation of `future<int>` `f1` using the `.then()` member
|
||||
function. This operation takes a lambda function which describes how `f2` should proceed after `f1` is ready.
|
||||
|
||||
|
||||
#include <boost/thread/future.hpp>
|
||||
using namespace boost;
|
||||
int main()
|
||||
{
|
||||
future<int> f1 = async([]() { return 123; });
|
||||
future<string> f2 = f1.then([](future<int> f) { return f.get().to_string(); // here .get() won't block });
|
||||
}
|
||||
|
||||
One key feature of this function is the ability to chain multiple asynchronous operations. In asynchronous programming,
|
||||
it's common to define a sequence of operations, in which each continuation executes only when the previous one completes.
|
||||
In some cases, the antecedent future produces a value that the continuation accepts as input. By using `future.then()`,
|
||||
creating a chain of continuations becomes straightforward and intuitive:
|
||||
|
||||
myFuture.then(...).then(...).then(...).
|
||||
|
||||
Some points to note are:
|
||||
|
||||
* Each continuation will not begin until the preceding has completed.
|
||||
* If an exception is thrown, the following continuation can handle it in a try-catch block
|
||||
|
||||
|
||||
Input Parameters:
|
||||
|
||||
* Lambda function: One option which can be considered is to take two functions, one for
|
||||
success and one for error handling. However this option has not been retained for the moment.
|
||||
The lambda function takes a future as its input which carries the exception
|
||||
through. This makes propagating exceptions straightforward. This approach also simplifies the chaining of continuations.
|
||||
* Scheduler: Providing an overload to `.then`, to take a scheduler reference places great flexibility over the execution
|
||||
of the future in the programmer's hand. As described above, often taking a launch policy is not sufficient for powerful
|
||||
asynchronous operations. The lifetime of the scheduler must outlive the continuation.
|
||||
* Launch policy: if the additional flexibility that the scheduler provides is not required.
|
||||
|
||||
Return values: The decision to return a future was based primarily on the ability to chain multiple continuations using
|
||||
`.then()`. This benefit of composability gives the programmer incredible control and flexibility over their code. Returning
|
||||
a `future` object rather than a `shared_future` is also a much cheaper operation thereby improving performance. A
|
||||
`shared_future` object is not necessary to take advantage of the chaining feature. It is also easy to go from a `future`
|
||||
to a `shared_future` when needed using future::share().
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[include future_ref.qbk]
|
||||
|
||||
[endsect]
|
||||
304
doc/glossary.xml
304
doc/glossary.xml
@@ -1,304 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<glossary id="thread.glossary" last-revision="$Date$">
|
||||
<title>Glossary</title>
|
||||
<para>Definitions are given in terms of the C++ Standard
|
||||
&cite.ISO98;. References to the standard are in the form [1.2.3/4], which
|
||||
represents the section number, with the paragraph number following the
|
||||
"/".</para>
|
||||
<para>Because the definitions are written in something akin to "standardese",
|
||||
they can be difficult to understand. The intent isn't to confuse, but rather
|
||||
to clarify the additional requirements &Boost.Thread; places on a C++
|
||||
implementation as defined by the C++ Standard.</para>
|
||||
<glossentry id="thread.glossary.thread">
|
||||
<glossterm>Thread</glossterm>
|
||||
<glossdef>
|
||||
<para>Thread is short for "thread of execution". A thread of execution is
|
||||
an execution environment [1.9/7] within the execution environment of a C++
|
||||
program [1.9]. The main() function [3.6.1] of the program is the initial
|
||||
function of the initial thread. A program in a multithreading environment
|
||||
always has an initial thread even if the program explicitly creates no
|
||||
additional threads.</para>
|
||||
<para>Unless otherwise specified, each thread shares all aspects of its
|
||||
execution environment with other threads in the program. Shared aspects of
|
||||
the execution environment include, but are not limited to, the
|
||||
following:</para>
|
||||
<itemizedlist>
|
||||
<listitem><para>Static storage duration (static, extern) objects
|
||||
[3.7.1].</para></listitem>
|
||||
<listitem><para>Dynamic storage duration (heap) objects [3.7.3]. Thus
|
||||
each memory allocation will return a unique addresses, regardless of the
|
||||
thread making the allocation request.</para></listitem>
|
||||
<listitem><para>Automatic storage duration (stack) objects [3.7.2]
|
||||
accessed via pointer or reference from another thread.</para></listitem>
|
||||
<listitem><para>Resources provided by the operating system. For example,
|
||||
files.</para></listitem>
|
||||
<listitem><para>The program itself. In other words, each thread is
|
||||
executing some function of the same program, not a totally different
|
||||
program.</para></listitem>
|
||||
</itemizedlist>
|
||||
<para>Each thread has its own:</para>
|
||||
<itemizedlist>
|
||||
<listitem><para>Registers and current execution sequence (program
|
||||
counter) [1.9/5].</para></listitem>
|
||||
<listitem><para>Automatic storage duration (stack) objects
|
||||
[3.7.2].</para></listitem>
|
||||
</itemizedlist>
|
||||
</glossdef>
|
||||
</glossentry>
|
||||
<glossentry id="thread.glossary.thread-safe">
|
||||
<glossterm>Thread-safe</glossterm>
|
||||
<glossdef>
|
||||
<para>A program is thread-safe if it has no <link
|
||||
linkend="thread.glossary.race-condition">race conditions</link>, does
|
||||
not <link linkend="thread.glossary.deadlock">deadlock</link>, and has
|
||||
no <link linkend="thread.glossary.priority-failure">priority
|
||||
failures</link>.</para>
|
||||
<para>Note that thread-safety does not necessarily imply efficiency, and
|
||||
than while some thread-safety violations can be determined statically at
|
||||
compile time, many thread-safety errors can only only be detected at
|
||||
runtime.</para>
|
||||
</glossdef>
|
||||
</glossentry>
|
||||
<glossentry id="thread.glossary.thread-state">
|
||||
<glossterm>Thread State</glossterm>
|
||||
<glossdef>
|
||||
<para>During the lifetime of a thread, it shall be in one of the following
|
||||
states:</para>
|
||||
<table>
|
||||
<title>Thread States</title>
|
||||
<tgroup cols="2" align="left">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>State</entry>
|
||||
<entry>Description</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>Ready</entry>
|
||||
<entry>Ready to run, but waiting for a processor.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Running</entry>
|
||||
<entry>Currently executing on a processor. Zero or more threads
|
||||
may be running at any time, with a maximum equal to the number of
|
||||
processors.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Blocked</entry>
|
||||
<entry>Waiting for some resource other than a processor which is
|
||||
not currently available, or for the completion of calls to library
|
||||
functions [1.9/6]. The term "waiting" is synonymous with
|
||||
"blocked"</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Terminated</entry>
|
||||
<entry>Finished execution but not yet detached or joined.</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
<para>Thread state transitions shall occur only as specified:</para>
|
||||
<table>
|
||||
<title>Thread States Transitions</title>
|
||||
<tgroup cols="3" align="left">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>From</entry>
|
||||
<entry>To</entry>
|
||||
<entry>Cause</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>[none]</entry>
|
||||
<entry>Ready</entry>
|
||||
<entry><para>Thread is created by a call to a library function.
|
||||
In the case of the initial thread, creation is implicit and
|
||||
occurs during the startup of the main() function [3.6.1].</para></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Ready</entry>
|
||||
<entry>Running</entry>
|
||||
<entry><para>Processor becomes available.</para></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Running</entry>
|
||||
<entry>Ready</entry>
|
||||
<entry>Thread preempted.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Running</entry>
|
||||
<entry>Blocked</entry>
|
||||
<entry>Thread calls a library function which waits for a resource or
|
||||
for the completion of I/O.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Running</entry>
|
||||
<entry>Terminated</entry>
|
||||
<entry>Thread returns from its initial function, calls a thread
|
||||
termination library function, or is canceled by some other thread
|
||||
calling a thread termination library function.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Blocked</entry>
|
||||
<entry>Ready</entry>
|
||||
<entry>The resource being waited for becomes available, or the
|
||||
blocking library function completes.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>Terminated</entry>
|
||||
<entry>[none]</entry>
|
||||
<entry>Thread is detached or joined by some other thread calling the
|
||||
appropriate library function, or by program termination
|
||||
[3.6.3].</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
<para>[Note: if a suspend() function is added to the threading library,
|
||||
additional transitions to the blocked state will have to be added to the
|
||||
above table.]</para>
|
||||
</glossdef>
|
||||
</glossentry>
|
||||
<glossentry id="thread.glossary.race-condition">
|
||||
<glossterm>Race Condition</glossterm>
|
||||
<glossdef>
|
||||
<para>A race condition is what occurs when multiple threads read from and write
|
||||
to the same memory without proper synchronization, resulting in an incorrect
|
||||
value being read or written. The result of a race condition may be a bit
|
||||
pattern which isn't even a valid value for the data type. A race condition
|
||||
results in undefined behavior [1.3.12].</para>
|
||||
<para>Race conditions can be prevented by serializing memory access using
|
||||
the tools provided by &Boost.Thread;.</para>
|
||||
</glossdef>
|
||||
</glossentry>
|
||||
<glossentry id="thread.glossary.deadlock">
|
||||
<glossterm>Deadlock</glossterm>
|
||||
<glossdef>
|
||||
<para>Deadlock is an execution state where for some set of threads, each
|
||||
thread in the set is blocked waiting for some action by one of the other
|
||||
threads in the set. Since each is waiting on the others, none will ever
|
||||
become ready again.</para>
|
||||
</glossdef>
|
||||
</glossentry>
|
||||
<glossentry id="thread.glossary.starvation">
|
||||
<glossterm>Starvation</glossterm>
|
||||
<glossdef>
|
||||
<para>The condition in which a thread is not making sufficient progress in
|
||||
its work during a given time interval.</para>
|
||||
</glossdef>
|
||||
</glossentry>
|
||||
<glossentry id="thread.glossary.priority-failure">
|
||||
<glossterm>Priority Failure</glossterm>
|
||||
<glossdef>
|
||||
<para>A priority failure (such as priority inversion or infinite overtaking)
|
||||
occurs when threads are executed in such a sequence that required work is not
|
||||
performed in time to be useful.</para>
|
||||
</glossdef>
|
||||
</glossentry>
|
||||
<glossentry id="thread.glossary.undefined-behavior">
|
||||
<glossterm>Undefined Behavior</glossterm>
|
||||
<glossdef>
|
||||
<para>The result of certain operations in &Boost.Thread; is undefined;
|
||||
this means that those operations can invoke almost any behavior when
|
||||
they are executed.</para>
|
||||
|
||||
<para>An operation whose behavior is undefined can work "correctly"
|
||||
in some implementations (i.e., do what the programmer thought it
|
||||
would do), while in other implementations it may exhibit almost
|
||||
any "incorrect" behavior--such as returning an invalid value,
|
||||
throwing an exception, generating an access violation, or terminating
|
||||
the process.</para>
|
||||
|
||||
<para>Executing a statement whose behavior is undefined is a
|
||||
programming error.</para>
|
||||
</glossdef>
|
||||
</glossentry>
|
||||
<glossentry id="thread.glossary.memory-visibility">
|
||||
<glossterm>Memory Visibility</glossterm>
|
||||
<glossdef>
|
||||
<para>An address [1.7] shall always point to the same memory byte,
|
||||
regardless of the thread or processor dereferencing the address.</para>
|
||||
<para>An object [1.8, 1.9] is accessible from multiple threads if it is of
|
||||
static storage duration (static, extern) [3.7.1], or if a pointer or
|
||||
reference to it is explicitly or implicitly dereferenced in multiple
|
||||
threads.</para>
|
||||
<para>For an object accessible from multiple threads, the value of the
|
||||
object accessed from one thread may be indeterminate or different from the
|
||||
value accessed from another thread, except under the conditions specified in
|
||||
the following table. For the same row of the table, the value of an object
|
||||
accessible at the indicated sequence point in thread A will be determinate
|
||||
and the same if accessed at or after the indicated sequence point in thread
|
||||
B, provided the object is not otherwise modified. In the table, the
|
||||
"sequence point at a call" is the sequence point after the evaluation of all
|
||||
function arguments [1.9/17], while the "sequence point after a call" is the
|
||||
sequence point after the copying of the returned value... [1.9/17].</para>
|
||||
<table>
|
||||
<title>Memory Visibility</title>
|
||||
<tgroup cols="2">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Thread A</entry>
|
||||
<entry>Thread B</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>The sequence point at a call to a library thread-creation
|
||||
function.</entry>
|
||||
<entry>The first sequence point of the initial function in the new
|
||||
thread created by the Thread A call.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>The sequence point at a call to a library function which
|
||||
locks a mutex, directly or by waiting for a condition
|
||||
variable.</entry>
|
||||
<entry>The sequence point after a call to a library function which
|
||||
unlocks the same mutex.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>The last sequence point before thread termination.</entry>
|
||||
<entry>The sequence point after a call to a library function which
|
||||
joins the terminated thread.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>The sequence point at a call to a library function which
|
||||
signals or broadcasts a condition variable.</entry>
|
||||
<entry>The sequence point after the call to the library function
|
||||
which was waiting on that same condition variable or signal.</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
<para>The architecture of the execution environment and the observable
|
||||
behavior of the abstract machine [1.9] shall be the same on all
|
||||
processors.</para>
|
||||
<para>The latitude granted by the C++ standard for an implementation to
|
||||
alter the definition of observable behavior of the abstract machine to
|
||||
include additional library I/O functions [1.9/6] is extended to include
|
||||
threading library functions.</para>
|
||||
<para>When an exception is thrown and there is no matching exception handler
|
||||
in the same thread, behavior is undefined. The preferred behavior is the
|
||||
same as when there is no matching exception handler in a program
|
||||
[15.3/9]. That is, terminate() is called, and it is implementation-defined
|
||||
whether or not the stack is unwound.</para>
|
||||
</glossdef>
|
||||
</glossentry>
|
||||
<section>
|
||||
<title>Acknowledgements</title>
|
||||
<para>This document was originally written by Beman Dawes, and then much
|
||||
improved by the incorporation of comments from William Kempf, who now
|
||||
maintains the contents.</para>
|
||||
<para>The visibility rules are based on &cite.Butenhof97;.</para>
|
||||
</section>
|
||||
</glossary>
|
||||
@@ -1,38 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.implementation_notes" last-revision="$Date$">
|
||||
<title>Implementation Notes</title>
|
||||
<section id="thread.implementation_notes.win32">
|
||||
<title>Win32</title>
|
||||
<para>
|
||||
In the current Win32 implementation, creating a boost::thread object
|
||||
during dll initialization will result in deadlock because the thread
|
||||
class constructor causes the current thread to wait on the thread that
|
||||
is being created until it signals that it has finished its initialization,
|
||||
and, as stated in the
|
||||
<ulink url="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/dllmain.asp">MSDN Library, "DllMain" article, "Remarks" section</ulink>,
|
||||
"Because DLL notifications are serialized, entry-point functions should not
|
||||
attempt to communicate with other threads or processes. Deadlocks may occur as a result."
|
||||
(Also see <ulink url="http://www.microsoft.com/msj/archive/S220.aspx">"Under the Hood", January 1996</ulink>
|
||||
for a more detailed discussion of this issue).
|
||||
</para>
|
||||
<para>
|
||||
The following non-exhaustive list details some of the situations that
|
||||
should be avoided until this issue can be addressed:
|
||||
<itemizedlist>
|
||||
<listitem>Creating a boost::thread object in DllMain() or in any function called by it.</listitem>
|
||||
<listitem>Creating a boost::thread object in the constructor of a global static object or in any function called by one.</listitem>
|
||||
<listitem>Creating a boost::thread object in MFC's CWinApp::InitInstance() function or in any function called by it.</listitem>
|
||||
<listitem>Creating a boost::thread object in the function pointed to by MFC's _pRawDllMain function pointer or in any function called by it.</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
@@ -1,6 +1,6 @@
|
||||
<!-- Copyright (c) 2002-2003 Beman Dawes, William E. Kempf.
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
|
||||
469
doc/internal_locking.qbk
Normal file
469
doc/internal_locking.qbk
Normal file
@@ -0,0 +1,469 @@
|
||||
[/
|
||||
/ Copyright (c) 2008,2014 Vicente J. Botet Escriba
|
||||
/
|
||||
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
|
||||
|
||||
[section Internal Locking]
|
||||
[note This tutorial is an adaptation of chapter Concurrency of the Object-Oriented Programming in the BETA Programming Language and of the paper of Andrei Alexandrescu "Multithreading and the C++ Type System" to the Boost library.]
|
||||
[section Concurrent threads of execution]
|
||||
|
||||
Consider, for example, modeling a bank account class that supports simultaneous deposits and withdrawals from multiple locations (arguably the "Hello, World" of multithreaded programming).
|
||||
|
||||
From here a component is a model of the `Callable` concept.
|
||||
|
||||
I C++11 (Boost) concurrent execution of a component is obtained by means of the `std::thread`(`boost::thread`):
|
||||
|
||||
boost::thread thread1(S);
|
||||
|
||||
where `S` is a model of `Callable`. The meaning of this expression is that execution of `S()` will take place concurrently with the current thread of execution executing the expression.
|
||||
|
||||
The following example includes a bank account of a person (Joe) and two components, one corresponding to a bank agent depositing money in Joe's account, and one representing Joe. Joe will only be withdrawing money from the account:
|
||||
|
||||
class BankAccount;
|
||||
|
||||
BankAccount JoesAccount;
|
||||
|
||||
void bankAgent()
|
||||
{
|
||||
for (int i =10; i>0; --i) {
|
||||
//...
|
||||
JoesAccount.Deposit(500);
|
||||
//...
|
||||
}
|
||||
}
|
||||
|
||||
void Joe() {
|
||||
for (int i =10; i>0; --i) {
|
||||
//...
|
||||
int myPocket = JoesAccount.Withdraw(100);
|
||||
std::cout << myPocket << std::endl;
|
||||
//...
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
//...
|
||||
boost::thread thread1(bankAgent); // start concurrent execution of bankAgent
|
||||
boost::thread thread2(Joe); // start concurrent execution of Joe
|
||||
thread1.join();
|
||||
thread2.join();
|
||||
return 0;
|
||||
}
|
||||
|
||||
From time to time, the `bankAgent` will deposit $500 in `JoesAccount`. `Joe` will similarly withdraw $100 from his account. These sentences describe that the `bankAgent` and `Joe` are executed concurrently.
|
||||
|
||||
[endsect]
|
||||
[section Internal locking]
|
||||
|
||||
The above example works well as long as the components `bankAgent` and `Joe` doesn't access `JoesAccount` at the same time. There is, however, no guarantee that this will not happen. We may use a mutex to guarantee exclusive access to each bank.
|
||||
|
||||
class BankAccount {
|
||||
boost::mutex mtx_;
|
||||
int balance_;
|
||||
public:
|
||||
void Deposit(int amount) {
|
||||
mtx_.lock();
|
||||
balance_ += amount;
|
||||
mtx_.unlock();
|
||||
}
|
||||
void Withdraw(int amount) {
|
||||
mtx_.lock();
|
||||
balance_ -= amount;
|
||||
mtx_.unlock();
|
||||
}
|
||||
int GetBalance() {
|
||||
mtx_.lock();
|
||||
int b = balance_;
|
||||
mtx_.unlock();
|
||||
return b;
|
||||
}
|
||||
};
|
||||
|
||||
Execution of the `Deposit` and `Withdraw` operations will no longer be able to make simultaneous access to balance.
|
||||
|
||||
A mutex is a simple and basic mechanism for obtaining synchronization. In the above example it is relatively easy to be convinced that the synchronization works correctly (in the absence of exception). In a system with several concurrent objects and several shared objects, it may be difficult to describe synchronization by means of mutexes. Programs that make heavy use of mutexes may be difficult to read and write. Instead, we shall introduce a number of generic classes for handling more complicated forms of synchronization and communication.
|
||||
|
||||
With the RAII idiom we can simplify a lot this using the scoped locks. In the code below, guard's constructor locks the passed-in object `mtx_`, and guard's destructor unlocks `mtx_`.
|
||||
|
||||
class BankAccount {
|
||||
boost::mutex mtx_; // explicit mutex declaration
|
||||
int balance_;
|
||||
public:
|
||||
void Deposit(int amount) {
|
||||
boost::lock_guard<boost::mutex> guard(mtx_);
|
||||
balance_ += amount;
|
||||
}
|
||||
void Withdraw(int amount) {
|
||||
boost::lock_guard<boost::mutex> guard(mtx_);
|
||||
balance_ -= amount;
|
||||
}
|
||||
int GetBalance() {
|
||||
boost::lock_guard<boost::mutex> guard(mtx_);
|
||||
return balance_;
|
||||
}
|
||||
};
|
||||
|
||||
The object-level locking idiom doesn't cover the entire richness of a threading model. For example, the model above is quite deadlock-prone when you try to coordinate multi-object transactions. Nonetheless, object-level locking is useful in many cases, and in combination with other mechanisms can provide a satisfactory solution to many threaded access problems in object-oriented programs.
|
||||
|
||||
[endsect]
|
||||
[section Internal and external locking]
|
||||
|
||||
The BankAccount class above uses internal locking. Basically, a class that uses internal locking guarantees that any concurrent calls to its public member functions don't corrupt an instance of that class. This is typically ensured by having each public member function acquire a lock on the object upon entry. This way, for any given object of that class, there can be only one member function call active at any moment, so the operations are nicely serialized.
|
||||
|
||||
This approach is reasonably easy to implement and has an attractive simplicity. Unfortunately, "simple" might sometimes morph into "simplistic."
|
||||
|
||||
Internal locking is insufficient for many real-world synchronization tasks. Imagine that you want to implement an ATM withdrawal transaction with the BankAccount class. The requirements are simple. The ATM transaction consists of two withdrawals-one for the actual money and one for the $2 commission. The two withdrawals must appear in strict sequence; that is, no other transaction can exist between them.
|
||||
|
||||
The obvious implementation is erratic:
|
||||
|
||||
void ATMWithdrawal(BankAccount& acct, int sum) {
|
||||
acct.Withdraw(sum);
|
||||
// preemption possible
|
||||
acct.Withdraw(2);
|
||||
}
|
||||
|
||||
The problem is that between the two calls above, another thread can perform another operation on the account, thus breaking the second design requirement.
|
||||
|
||||
In an attempt to solve this problem, let's lock the account from the outside during the two operations:
|
||||
|
||||
void ATMWithdrawal(BankAccount& acct, int sum) {
|
||||
boost::lock_guard<boost::mutex> guard(acct.mtx_); 1
|
||||
acct.Withdraw(sum);
|
||||
acct.Withdraw(2);
|
||||
}
|
||||
|
||||
Notice that the code above doesn't compile, the `mtx_` field is private.
|
||||
We have two possibilities:
|
||||
|
||||
* make `mtx_` public which seems odd
|
||||
* make the `BankAccount` lockable by adding the lock/unlock functions
|
||||
|
||||
We can add these functions explicitly
|
||||
|
||||
class BankAccount {
|
||||
boost::mutex mtx_;
|
||||
int balance_;
|
||||
public:
|
||||
void Deposit(int amount) {
|
||||
boost::lock_guard<boost::mutex> guard(mtx_);
|
||||
balance_ += amount;
|
||||
}
|
||||
void Withdraw(int amount) {
|
||||
boost::lock_guard<boost::mutex> guard(mtx_);
|
||||
balance_ -= amount;
|
||||
}
|
||||
void lock() {
|
||||
mtx_.lock();
|
||||
}
|
||||
void unlock() {
|
||||
mtx_.unlock();
|
||||
}
|
||||
};
|
||||
|
||||
or inheriting from a class which add these lockable functions.
|
||||
|
||||
The `basic_lockable_adapter` class helps to define the `BankAccount` class as
|
||||
|
||||
class BankAccount
|
||||
: public basic_lockable_adapter<mutex>
|
||||
{
|
||||
int balance_;
|
||||
public:
|
||||
void Deposit(int amount) {
|
||||
boost::lock_guard<BankAccount> guard(*this);
|
||||
balance_ += amount;
|
||||
}
|
||||
void Withdraw(int amount) {
|
||||
boost::lock_guard<BankAccount> guard(*this);
|
||||
balance_ -= amount;
|
||||
}
|
||||
int GetBalance() {
|
||||
boost::lock_guard<BankAccount> guard(*this);
|
||||
return balance_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
and the code that doesn't compiles becomes
|
||||
|
||||
void ATMWithdrawal(BankAccount& acct, int sum) {
|
||||
boost::lock_guard<BankAccount> guard(acct);
|
||||
acct.Withdraw(sum);
|
||||
acct.Withdraw(2);
|
||||
}
|
||||
|
||||
Notice that now acct is being locked by Withdraw after it has already been locked by guard. When running such code, one of two things happens.
|
||||
|
||||
* Your mutex implementation might support the so-called recursive mutex semantics. This means that the same thread can lock the same mutex several times successfully. In this case, the implementation works but has a performance overhead due to unnecessary locking. (The locking/unlocking sequence in the two Withdraw calls is not needed but performed anyway-and that costs time.)
|
||||
* Your mutex implementation might not support recursive locking, which means that as soon as you try to acquire it the second time, it blocks-so the ATMWithdrawal function enters the dreaded deadlock.
|
||||
|
||||
As `boost::mutex` is not recursive, we need to use its recursive version `boost::recursive_mutex`.
|
||||
|
||||
class BankAccount
|
||||
: public basic_lockable_adapter<recursive_mutex>
|
||||
{
|
||||
|
||||
// ...
|
||||
};
|
||||
|
||||
The caller-ensured locking approach is more flexible and the most efficient, but very dangerous. In an implementation using caller-ensured locking, BankAccount still holds a mutex, but its member functions don't manipulate it at all. Deposit and Withdraw are not thread-safe anymore. Instead, the client code is responsible for locking BankAccount properly.
|
||||
|
||||
class BankAccount
|
||||
: public basic_lockable_adapter<boost:mutex> {
|
||||
int balance_;
|
||||
public:
|
||||
void Deposit(int amount) {
|
||||
balance_ += amount;
|
||||
}
|
||||
void Withdraw(int amount) {
|
||||
balance_ -= amount;
|
||||
}
|
||||
};
|
||||
|
||||
Obviously, the caller-ensured locking approach has a safety problem. BankAccount's implementation code is finite, and easy to reach and maintain, but there's an unbounded amount of client code that manipulates BankAccount objects. In designing applications, it's important to differentiate between requirements imposed on bounded code and unbounded code. If your class makes undue requirements on unbounded code, that's usually a sign that encapsulation is out the window.
|
||||
|
||||
To conclude, if in designing a multi-threaded class you settle on internal locking, you expose yourself to inefficiency or deadlocks. On the other hand, if you rely on caller-provided locking, you make your class error-prone and difficult to use. Finally, external locking completely avoids the issue by leaving it all to the client code.
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[/
|
||||
[section Monitors]
|
||||
|
||||
The use of `mutex` and `lockers`, as in `BankAccount`, is a common way of defining objects shared by two or more concurrent components. The basic_lockable_adapter class was a first step.
|
||||
We shall therefore introduce an abstraction that makes it easier to define such objects.
|
||||
The following class describes a so-called monitor pattern.
|
||||
|
||||
template <
|
||||
typename Lockable=mutex
|
||||
>
|
||||
class basic_monitor : protected basic_lockable_adapter<Lockable> { // behaves like an BasicLockable for the derived classes
|
||||
protected:
|
||||
typedef unspecified synchronizer; // is an strict lock guard
|
||||
};
|
||||
|
||||
[/shared_monitor]
|
||||
[/monitor]
|
||||
|
||||
A basic_monitor object behaves like a `BasicLockable` object but only for the inheriting classes.
|
||||
Protected inheritance from lockable_adapter provide to all the derived classes all BasicLockable operations. In addition has a protected nested class, synchronizer, used when defining the monitor operations to synchronize the access critical regions. The BankAccount may be described using Monitor in the following way:
|
||||
|
||||
class BankAccount : protected basic_monitor<>
|
||||
{
|
||||
protected:
|
||||
int balance_;
|
||||
public:
|
||||
BankAccount() : balance_(0) {}
|
||||
BankAccount(const BankAccount &rhs) {
|
||||
synchronizer _(*rhs.mutex());
|
||||
balance_=rhs.balance_;
|
||||
}
|
||||
|
||||
BankAccount& operator=(BankAccount &rhs)
|
||||
{
|
||||
if(&rhs == this) return *this;
|
||||
|
||||
int balance=0;
|
||||
{
|
||||
synchronizer _(*rhs.mutex());
|
||||
balance=rhs.balance_;
|
||||
}
|
||||
synchronizer _(*this->mutex());
|
||||
balance_=balance;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Deposit(int amount) {
|
||||
synchronizer _(*this->mutex());
|
||||
balance_ += amount;
|
||||
}
|
||||
int Withdraw(int amount) {
|
||||
synchronizer _(*this->mutex());
|
||||
balance_ -= amount;
|
||||
return amount;
|
||||
}
|
||||
int GetBalance() {
|
||||
synchronizer _(*this->mutex());
|
||||
return balance_;
|
||||
}
|
||||
};
|
||||
|
||||
In the following, a monitor means some sub-class of monitor. A synchronized operation means an operation using the synchronizer guard defined within some monitor. Monitor is one example of a high-level concurrency abstraction that can be defined by means of mutexes.
|
||||
|
||||
|
||||
[section Monitor Conditions]
|
||||
|
||||
It may happen that a component executing an entry operation of a monitor is unable to continue execution due to some condition not being fulfilled. Consider, for instance, a bounded buffer of characters. Such a buffer may be implemented as a monitor with two operations Push and Pull: the Puss operation cannot be executed if the buffer is full, and the Pull operation cannot be executed if the buffer is empty. A sketch of such a buffer monitor may look as
|
||||
follows:
|
||||
|
||||
class sync_buffer {
|
||||
boost::mutex mtx_; 1
|
||||
public:
|
||||
...
|
||||
bool full() { return in_==out_; }
|
||||
bool empty() { return in_==(out_%size)+1; }
|
||||
void push(T& v) {
|
||||
// wait if buffer is full
|
||||
data_[in_]=v;
|
||||
in_ = (in_% size)+1;
|
||||
}
|
||||
T pull() {
|
||||
// wait if buffer is empty
|
||||
out_ = (out_% size)+1;
|
||||
return data_[out_];
|
||||
}
|
||||
};
|
||||
|
||||
The meaning of a wait is that the calling component is delayed until the condition becomes true. We can do that using Boost.Thread condition variables like:
|
||||
|
||||
template <typename T, unsigned size>
|
||||
class sync_buffer
|
||||
{
|
||||
typedef boost::mutex mutex_type;
|
||||
typedef boost::condition_variable condition_type;
|
||||
typedef boost::unique_lock<mutex_type> unique_lock_type;
|
||||
mutex_type mtx_;
|
||||
condition_type not_full_;
|
||||
condition_type not_empty_;
|
||||
|
||||
T data_[size+1];
|
||||
unsigned in_, out_;
|
||||
|
||||
public:
|
||||
sync_buffer():in_(0), out_(0) {}
|
||||
|
||||
bool full() { return out_==(in_+1)%(size+1); }
|
||||
bool empty() { return out_==in_; }
|
||||
|
||||
unsigned get_in() {return in_;}
|
||||
unsigned get_out() {return out_;}
|
||||
void push(T v) {
|
||||
unique_lock_type guard(mtx_); 1
|
||||
while (full()) { 2
|
||||
not_full_.wait(guard);
|
||||
}
|
||||
data_[in_]=v;
|
||||
in_ = (in_+1)% (size+1);
|
||||
not_empty_.notify_one(); 3
|
||||
}
|
||||
|
||||
T pull() {
|
||||
unique_lock_type guard(mtx_); 4
|
||||
while (empty()) { 5
|
||||
not_empty_.wait(guard);
|
||||
}
|
||||
unsigned idx = out_;
|
||||
out_ = (out_+1)% (size+1);
|
||||
not_full_.notify_one(); 6
|
||||
return data_[idx];
|
||||
}
|
||||
};
|
||||
|
||||
The Monitor class replace the nested synchronizer unique_lock with the class `condition_unique_lock` for this purpose:
|
||||
|
||||
template <
|
||||
typename Lockable,
|
||||
class Condition=condition_safe<typename best_condition<Lockable>::type >
|
||||
, typename ScopeTag=typename scope_tag<Lockable>::type
|
||||
>
|
||||
class condition_unique_lock
|
||||
: protected unique_lock<Lockable,ScopeTag>
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT((LockableConcept<Lockable>));
|
||||
public:
|
||||
typedef Lockable lockable_type;
|
||||
typedef Condition condition;
|
||||
|
||||
explicit condition_unique_lock(lockable_type& obj); 1
|
||||
condition_unique_lock(lockable_type& obj, condition &cond); 2
|
||||
template <typename Predicate>
|
||||
condition_unique_lock(lockable_type& obj, condition &cond, Predicate pred); 3
|
||||
~condition_unique_lock() 4
|
||||
|
||||
typedef bool (condition_unique_lock::*bool_type)() const; 5
|
||||
operator bool_type() const; 6
|
||||
bool operator!() const { return false; } 7
|
||||
bool owns_lock() const { return true; } 8
|
||||
bool is_locking(lockable_type* l) const 9
|
||||
|
||||
void relock_on(condition & cond);
|
||||
template<typename Clock, typename Duration>
|
||||
void relock_until(condition & cond, chrono::time_point<Clock, Duration> const& abs_time);
|
||||
template<typename duration_type>
|
||||
void relock_on_for(condition & cond, duration_type const& rel_time);
|
||||
|
||||
template<typename Predicate>
|
||||
void relock_when(condition &cond, Predicate pred);
|
||||
template<typename Predicate>
|
||||
template<typename Clock, typename Duration>
|
||||
void relock_when_until(condition &cond, Predicate pred,
|
||||
chrono::time_point<Clock, Duration> const& abs_time);
|
||||
template<typename Predicate, typename duration_type>
|
||||
void relock_when_for(condition &cond, Predicate pred,
|
||||
duration_type const& rel_time);
|
||||
|
||||
10
|
||||
};
|
||||
|
||||
|
||||
We may now give the complete version of the buffer class. The content of the buffer is: `data_[out_+1], data_[out_+2], ... data_R[in_-1]` where all the indexes are modulo size. The buffer is full if `in_=out_` and it is empty if `in_=(out_+1)%size`.
|
||||
|
||||
template <typename T, unsigned size>
|
||||
class sync_buffer : protected basic_monitor<>
|
||||
{
|
||||
condition not_full_;
|
||||
condition not_empty_;
|
||||
|
||||
T data_[size+1];
|
||||
unsigned in_, out_;
|
||||
|
||||
struct not_full {
|
||||
explicit not_full(sync_buffer &b):that_(b){};
|
||||
bool operator()() const { return !that_.full(); }
|
||||
sync_buffer &that_;
|
||||
};
|
||||
struct not_empty {
|
||||
explicit not_empty(sync_buffer &b):that_(b){};
|
||||
bool operator()() const { return !that_.empty(); }
|
||||
sync_buffer &that_;
|
||||
};
|
||||
public:
|
||||
BOOST_COPY_CONSTRUCTOR_DELETE(sync_buffer) 1
|
||||
BOOST_COPY_ASSIGNEMENT_DELETE(sync_buffer) 2
|
||||
sync_buffer():in_(0), out_(0) {}
|
||||
|
||||
bool full() { return out_==(in_+1)%(size+1); }
|
||||
bool empty() { return out_==in_; }
|
||||
|
||||
unsigned get_in() {return in_;}
|
||||
unsigned get_out() {return out_;}
|
||||
|
||||
void push(T v) {
|
||||
synchronizer _(*this->mutex(), not_full_, not_full(*this)); 3
|
||||
data_[in_]=v;
|
||||
in_ = (in_+1)% (size+1);
|
||||
not_empty_.notify_one(); 4
|
||||
}
|
||||
|
||||
T pull() {
|
||||
synchronizer _(*this->mutex(), not_empty_, not_empty(*this)); 5
|
||||
unsigned idx = out_;
|
||||
out_ = (out_+1)% (size+1);
|
||||
not_full_.notify_one(); 6
|
||||
return data_[idx];
|
||||
}
|
||||
};
|
||||
|
||||
Monitors and conditions are useful for describing simple cases of shared objects (by simple we mean a limited use of conditions). If the conditions for delaying a calling component become complicated, the monitor may similarly become difficult to program and read.
|
||||
|
||||
[endsect] [/Monitor Conditions]
|
||||
|
||||
[endsect] [/Monitors]
|
||||
]
|
||||
|
||||
[endsect] [/Internal Locking]
|
||||
|
||||
|
||||
419
doc/latch.qbk
Normal file
419
doc/latch.qbk
Normal file
@@ -0,0 +1,419 @@
|
||||
[/
|
||||
(C) Copyright 2013 Vicente J. Botet Escriba.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:latches Latches -- EXPERIMENTAL]
|
||||
|
||||
[////////////////////]
|
||||
[section Introdcution]
|
||||
|
||||
Latches are a thread co-ordination mechanism that allow one or more threads to block until one or more threads have reached a point.
|
||||
|
||||
[/
|
||||
An individual latch is a reusable object; once the operation has been completed, the threads can re-use the same barrier. It is thus useful for managing repeated tasks handled by multiple threads.
|
||||
|
||||
A completion latch is like a latch that allows to associate a completion function which will be called once the internal counter reaches the value 0 and all the consumer threads have taken care of the notification.
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[////////////////]
|
||||
[section Examples]
|
||||
|
||||
Sample use cases for the latch include:
|
||||
|
||||
* Setting multiple threads to perform a task, and then waiting until all threads have reached a common point.
|
||||
* Creating multiple threads, which wait for a signal before advancing beyond a common point.
|
||||
|
||||
An example of the first use case would be as follows:
|
||||
|
||||
void DoWork(thread_pool* pool) {
|
||||
latch completion_latch(NTASKS);
|
||||
for (int i = 0; i < NTASKS; ++i) {
|
||||
pool->submit([&] {
|
||||
// perform work
|
||||
...
|
||||
completion_latch.count_down();
|
||||
}));
|
||||
}
|
||||
// Block until work is done
|
||||
completion_latch.wait();
|
||||
}
|
||||
|
||||
An example of the second use case is shown below. We need to load data and then process it using a number of threads. Loading the data is I/O bound, whereas starting threads and creating data structures is CPU bound. By running these in parallel, throughput can be increased.
|
||||
|
||||
void DoWork() {
|
||||
latch start_latch(1);
|
||||
vector<thread*> workers;
|
||||
for (int i = 0; i < NTHREADS; ++i) {
|
||||
workers.push_back(new thread([&] {
|
||||
// Initialize data structures. This is CPU bound.
|
||||
...
|
||||
start_latch.wait();
|
||||
// perform work
|
||||
...
|
||||
}));
|
||||
}
|
||||
// Load input data. This is I/O bound.
|
||||
...
|
||||
// Threads can now start processing
|
||||
start_latch.count_down();
|
||||
}
|
||||
|
||||
[/
|
||||
The completion latches can be used to co-ordinate also a set of threads carrying out a repeated task. The number of threads can be adjusted dynamically to respond to changing requirements.
|
||||
|
||||
In the example below, a number of threads are performing a multi-stage task. Some tasks may require fewer steps than others, meaning that some threads may finish before others. We reduce the number of threads waiting on the latch when this happens.
|
||||
|
||||
void DoWork() {
|
||||
Tasks& tasks;
|
||||
size_t initial_threads;
|
||||
atomic<size_t> current_threads(initial_threads)
|
||||
vector<thread*> workers;
|
||||
|
||||
// Create a barrier, and set a lambda that will be invoked every time the
|
||||
// barrier counts down. If one or more active threads have completed,
|
||||
// reduce the number of threads.
|
||||
completion_latch task_barrier(n_threads);
|
||||
task_barrier.then([&] {
|
||||
task_barrier.reset(current_threads);
|
||||
});
|
||||
|
||||
for (int i = 0; i < n_threads; ++i) {
|
||||
workers.push_back(new thread([&] {
|
||||
bool active = true;
|
||||
while(active) {
|
||||
Task task = tasks.get();
|
||||
// perform task
|
||||
...
|
||||
if (finished(task)) {
|
||||
current_threads--;
|
||||
active = false;
|
||||
}
|
||||
task_barrier.count_down_and_wait();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Read each stage of the task until all stages are complete.
|
||||
while (!finished()) {
|
||||
GetNextStage(tasks);
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////]
|
||||
[section:latch Class `latch`]
|
||||
|
||||
#include <boost/thread/latch.hpp>
|
||||
|
||||
class latch
|
||||
{
|
||||
public:
|
||||
latch(latch const&) = delete;
|
||||
latch& operator=(latch const&) = delete;
|
||||
|
||||
latch(std::size_t count);
|
||||
~latch();
|
||||
|
||||
void wait();
|
||||
bool try_wait();
|
||||
template <class Rep, class Period>
|
||||
cv_status wait_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class lock_type, class Clock, class Duration>
|
||||
cv_status wait_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
void count_down();
|
||||
void count_down_and_wait();
|
||||
|
||||
};
|
||||
|
||||
|
||||
[/
|
||||
void reset(std::size_t count);
|
||||
]
|
||||
|
||||
A latch maintains an internal counter that is initialized when the latch is created. One or more threads may block waiting until the counter is decremented to 0.
|
||||
|
||||
Instances of __latch__ are not copyable or movable.
|
||||
|
||||
[///////////////////]
|
||||
[section Constructor `latch(std::size_t)`]
|
||||
|
||||
latch(std::size_t count);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Construct a latch with is initial value for the internal counter.]]
|
||||
|
||||
[[Note:] [The counter could be zero.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[//////////////////]
|
||||
[section Destructor `~latch()`]
|
||||
|
||||
~latch();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Precondition:] [No threads are waiting or invoking count_down on `*this`.]]
|
||||
|
||||
[[Effects:] [Destroys `*this` latch.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[/////////////////////////////////////]
|
||||
[section:wait Member Function `wait()`]
|
||||
|
||||
void wait();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Block the calling thread until the internal count reaches the value zero. Then all waiting threads
|
||||
are unblocked. ]]
|
||||
|
||||
[[Throws:] [
|
||||
- __thread_resource_error__ if an error occurs.
|
||||
|
||||
- __thread_interrupted__ if the wait was interrupted by a call to __interrupt__ on the __thread__ object associated with the current thread of execution.
|
||||
]]
|
||||
|
||||
[[Notes:] [`wait()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[/////////////////////////////////////////////]
|
||||
[section:try_wait Member Function `try_wait()`]
|
||||
|
||||
bool try_wait();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Returns:] [Returns true if the internal count is 0, and false otherwise. Does not block the calling thread. ]]
|
||||
|
||||
[[Throws:] [
|
||||
- __thread_resource_error__ if an error occurs.
|
||||
]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[//////////////////////////////////////////////]
|
||||
[section:wait_for Member Function `wait_for() `]
|
||||
|
||||
template <class Rep, class Period>
|
||||
cv_status wait_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Block the calling thread until the internal count reaches the value zero or the duration has been elapsed. If no timeout, all waiting threads are unblocked. ]]
|
||||
[[Returns:] [cv_status::no_timeout if the internal count is 0, and cv_status::timeout if duration has been elapsed. ]]
|
||||
|
||||
[[Throws:] [
|
||||
- __thread_resource_error__ if an error occurs.
|
||||
|
||||
- __thread_interrupted__ if the wait was interrupted by a call to __interrupt__ on the __thread__ object associated with the current thread of execution.
|
||||
]]
|
||||
|
||||
[[Notes:] [`wait_for()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[/////////////////////////////////////////////////]
|
||||
[section:wait_until Member Function `wait_until()`]
|
||||
|
||||
template <class lock_type, class Clock, class Duration>
|
||||
cv_status wait_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Block the calling thread until the internal count reaches the value zero or the time_point has been reached. If no timeout, all waiting threads are unblocked. ]]
|
||||
[[Returns:] [cv_status::no_timeout if the internal count is 0, and cv_status::timeout if time_point has been reached.]]
|
||||
|
||||
[[Throws:] [
|
||||
- __thread_resource_error__ if an error occurs.
|
||||
|
||||
- __thread_interrupted__ if the wait was interrupted by a call to __interrupt__ on the __thread__ object associated with the current thread of execution.
|
||||
]]
|
||||
|
||||
[[Notes:] [`wait_until()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[/////////////////////////////////////////////////]
|
||||
[section:count_down Member Function `count_down()`]
|
||||
|
||||
void count_down();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [The internal counter is non zero.]]
|
||||
[[Effects:] [Decrements the internal count by 1, and returns. If the count reaches 0, any threads blocked in wait() will be released. ]]
|
||||
|
||||
[[Throws:] [
|
||||
- __thread_resource_error__ if an error occurs.
|
||||
|
||||
- __thread_interrupted__ if the wait was interrupted by a call to __interrupt__ on the __thread__ object associated with the current thread of execution.
|
||||
]]
|
||||
[[Notes:] [`count_down()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////////////////////////////////////////////]
|
||||
[section:count_down_and_wait Member Function `count_down_and_wait()`]
|
||||
|
||||
void count_down_and_wait();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [The internal counter is non zero.]]
|
||||
[[Effects:] [Decrements the internal count by 1. If the resulting count is not 0, blocks the calling thread until the internal count is decremented to 0 by one or more other threads calling count_down() or count_down_and_wait(). ]]
|
||||
|
||||
[[Throws:] [
|
||||
- __thread_resource_error__ if an error occurs.
|
||||
|
||||
- __thread_interrupted__ if the wait was interrupted by a call to __interrupt__ on the __thread__ object associated with the current thread of execution.
|
||||
]]
|
||||
[[Notes:] [`count_down_and_wait()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////////////////]
|
||||
[
|
||||
[section:reset Member Function `reset()`]
|
||||
|
||||
reset( size_t );
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [This function may only be invoked when there are no other threads currently inside the waiting functions.]]
|
||||
|
||||
[[Returns:] [Resets the latch with a new value for the initial thread count. ]]
|
||||
|
||||
[[Throws:] [
|
||||
- __thread_resource_error__ if an error occurs.
|
||||
]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
]
|
||||
[endsect] [/ latch]
|
||||
|
||||
[/
|
||||
[//////////////////////////////////////////////////]
|
||||
[section:completion_latch Class `completion_latch `]
|
||||
|
||||
#include <boost/thread/completion_latch.hpp>
|
||||
|
||||
class completion_latch
|
||||
{
|
||||
public:
|
||||
typedef 'implementation defined' completion_function;
|
||||
|
||||
completion_latch(completion_latch const&) = delete;
|
||||
completion_latch& operator=(completion_latch const&) = delete;
|
||||
|
||||
completion_latch(std::size_t count);
|
||||
template <typename F>
|
||||
completion_latch(std::size_t count, F&& funct);
|
||||
~completion_latch();
|
||||
|
||||
void wait();
|
||||
bool try_wait();
|
||||
template <class Rep, class Period>
|
||||
cv_status wait_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class lock_type, class Clock, class Duration>
|
||||
cv_status wait_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
void count_down();
|
||||
void count_down_and_wait();
|
||||
void reset(std::size_t count);
|
||||
template <typename F>
|
||||
completion_function then(F&& funct);
|
||||
};
|
||||
|
||||
|
||||
A completion latch is like a latch that allows to associate a completion function which will be called once the internal counter reaches the value 0 and all the consumer threads have taken care of the notification.
|
||||
|
||||
Instances of completion_latch are not copyable or movable.
|
||||
|
||||
Only the additional functions are documented.
|
||||
|
||||
[/////////////////////]
|
||||
[section:c Constructor]
|
||||
|
||||
completion_latch(std::size_t count);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Construct a completion_latch with is initial value for the internal counter and a noop completion function.]]
|
||||
|
||||
[[Note:] [The counter could be zero and rest later.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////////////////////////]
|
||||
[section:cf Constructor with completion function]
|
||||
|
||||
template <typename F>
|
||||
completion_latch(std::size_t count, F&& funct);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Construct a completion_latch with is initial value for the internal counter and the completion function `funct`.]]
|
||||
|
||||
[[Note:] [The counter could be zero and reset later.]]
|
||||
|
||||
[[Throws:] [
|
||||
|
||||
- Any exception thrown by the copy/move construction of funct.
|
||||
|
||||
]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////////////]
|
||||
[section:then Member Function `then`]
|
||||
|
||||
template <typename F>
|
||||
completion_function then(F&& funct);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [This function may only be invoked when there are no other threads currently inside the waiting functions. It may also be invoked from within the registered completion function. ]]
|
||||
|
||||
[[Effects:] [Associates the parameter `funct` as completion function of the latch. The next time the internal count reaches 0, this function will be invoked.]]
|
||||
[[Returns:] [The old completion function.]]
|
||||
|
||||
[[Throws:] [
|
||||
- __thread_resource_error__ if an error occurs.
|
||||
|
||||
- Any exception thrown by the copy/move construction of completion functions.
|
||||
]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect] [/ completion_latch]
|
||||
]
|
||||
|
||||
[endsect] [/ Latches]
|
||||
117
doc/lockable_adapter.qbk
Normal file
117
doc/lockable_adapter.qbk
Normal file
@@ -0,0 +1,117 @@
|
||||
[/
|
||||
(C) Copyright 2008-2013 Vicente J. Botet Escriba
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[/==========================================================================================]
|
||||
[section:lockable_adapter_hpp Header `<boost/thread/lockable_adapter.hpp>`]
|
||||
[/==========================================================================================]
|
||||
|
||||
namespace boost {
|
||||
template <typename Lockable> class basic_lockable_adapter;
|
||||
template <typename Lockable> class lockable_adapter;
|
||||
template <typename TimedLock> class timed_lockable_adapter;
|
||||
template <typename SharableLock> class shared_lockable_adapter;
|
||||
template <typename UpgradableLock> class upgrade_lockable_adapter;
|
||||
}
|
||||
|
||||
[section Template Class `basic_lockable_adapter<>`]
|
||||
|
||||
template <typename Lockable>
|
||||
class basic_lockable_adapter {
|
||||
public:
|
||||
basic_lockable_adapter(basic_lockable_adapter const&) = delete
|
||||
basic_lockable_adapter& opearator=(basic_lockable_adapter const&) = delete
|
||||
|
||||
typedef Lockable mutex_type;
|
||||
|
||||
basic_lockable_adapter() {}
|
||||
void lock();
|
||||
void unlock();
|
||||
bool try_lock();
|
||||
};
|
||||
|
||||
[endsect]
|
||||
[section Template Class `lockable_adapter<>`]
|
||||
|
||||
template <typename Lockable>
|
||||
class lockable_adapter : : public basic_lockable_adapter<Lockable> {
|
||||
public:
|
||||
lockable_adapter() {}
|
||||
|
||||
bool try_lock();
|
||||
};
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Template Class `timed_lockable_adapter<>`]
|
||||
|
||||
template <typename TimedLock>
|
||||
class timed_lockable_adapter : public lockable_adapter<TimedLock> {
|
||||
public:
|
||||
timed_lockable_adapter() {}
|
||||
|
||||
bool try_lock_until(system_time const & abs_time);
|
||||
template<typename TimeDuration>
|
||||
bool try_lock_for(TimeDuration const & relative_time);
|
||||
|
||||
void lock_until(system_time const & abs_time);
|
||||
template<typename TimeDuration>
|
||||
void lock_for(TimeDuration const & relative_time);
|
||||
};
|
||||
|
||||
[endsect]
|
||||
[section Template Class `shared_lockable_adapter<>`]
|
||||
|
||||
template <typename SharableLock>
|
||||
class shared_lockable_adapter : public timed_lockable_adapter<SharableLock> {
|
||||
public:
|
||||
shared_lockable_adapter() {}
|
||||
void lock_shared();
|
||||
bool try_lock_shared();
|
||||
void unlock_shared();
|
||||
|
||||
bool try_lock_shared_until(system_time const& t);
|
||||
template<typename TimeDuration>
|
||||
bool try_lock_shared_for(TimeDuration const& t);
|
||||
|
||||
template<typename TimeDuration>
|
||||
void lock_shared_for(TimeDuration const& t);
|
||||
void lock_shared_until(system_time const& t);
|
||||
};
|
||||
|
||||
|
||||
[endsect]
|
||||
[section Template Class `upgrade_lockable_adapter<>`]
|
||||
|
||||
template <typename UpgradableLock>
|
||||
class upgrade_lockable_adapter : public shared_lockable_adapter<UpgradableLock>{
|
||||
public:
|
||||
upgrade_lockable_adapter();
|
||||
|
||||
void lock_upgrade();
|
||||
bool try_lock_upgrade();
|
||||
void unlock_upgrade();
|
||||
|
||||
void unlock_upgrade_and_lock();
|
||||
void unlock_and_lock_upgrade();
|
||||
void unlock_and_lock_shared();
|
||||
void unlock_upgrade_and_lock_shared();
|
||||
|
||||
bool try_lock_upgrade_until(system_time const&t);
|
||||
template<typename TimeDuration>
|
||||
bool try_lock_upgrade_for(TimeDuration const&t);
|
||||
void lock_upgrade_until(system_time const&t);
|
||||
template<typename TimeDuration>
|
||||
void lock_upgrade_for(TimeDuration const&t);
|
||||
};
|
||||
|
||||
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
@@ -1,309 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/mutex.hpp"
|
||||
last-revision="$Date$">
|
||||
<namespace name="boost">
|
||||
<class name="mutex">
|
||||
<purpose>
|
||||
<para>The <classname>mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.Mutex">Mutex</link> concept.</para>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<para>The <classname>mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.Mutex">Mutex</link> concept.
|
||||
It should be used to synchronize access to shared resources using
|
||||
<link linkend="thread.concepts.unspecified-locking-strategy">Unspecified</link>
|
||||
locking mechanics.</para>
|
||||
|
||||
<para>For classes that model related mutex concepts, see
|
||||
<classname>try_mutex</classname> and <classname>timed_mutex</classname>.</para>
|
||||
|
||||
<para>For <link linkend="thread.concepts.recursive-locking-strategy">Recursive</link>
|
||||
locking mechanics, see <classname>recursive_mutex</classname>,
|
||||
<classname>recursive_try_mutex</classname>, and <classname>recursive_timed_mutex</classname>.
|
||||
</para>
|
||||
|
||||
<para>The <classname>mutex</classname> class supplies the following typedef,
|
||||
which <link linkend="thread.concepts.lock-models">models</link>
|
||||
the specified locking strategy:
|
||||
|
||||
<informaltable>
|
||||
<tgroup cols="2" align="left">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Lock Name</entry>
|
||||
<entry>Lock Concept</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>scoped_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedLock">ScopedLock</link></entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
</para>
|
||||
|
||||
<para>The <classname>mutex</classname> class uses an
|
||||
<link linkend="thread.concepts.unspecified-locking-strategy">Unspecified</link>
|
||||
locking strategy, so attempts to recursively lock a <classname>mutex</classname>
|
||||
object or attempts to unlock one by threads that don't own a lock on it result in
|
||||
<emphasis role="bold">undefined behavior</emphasis>.
|
||||
This strategy allows implementations to be as efficient as possible
|
||||
on any given platform. It is, however, recommended that
|
||||
implementations include debugging support to detect misuse when
|
||||
<code>NDEBUG</code> is not defined.</para>
|
||||
|
||||
<para>Like all
|
||||
<link linkend="thread.concepts.mutex-models">mutex models</link>
|
||||
in &Boost.Thread;, <classname>mutex</classname> leaves the
|
||||
<link linkend="thread.concepts.sheduling-policies">scheduling policy</link>
|
||||
as <link linkend="thread.concepts.unspecified-scheduling-policy">Unspecified</link>.
|
||||
Programmers should make no assumptions about the order in which
|
||||
waiting threads acquire a lock.</para>
|
||||
</description>
|
||||
|
||||
<inherit access="private">
|
||||
<type><classname>boost::noncopyable</classname></type>
|
||||
<purpose>Exposition only</purpose>
|
||||
</inherit>
|
||||
|
||||
<typedef name="scoped_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<constructor>
|
||||
<effects>Constructs a <classname>mutex</classname> object.
|
||||
</effects>
|
||||
|
||||
<postconditions><code>*this</code> is in an unlocked state.
|
||||
</postconditions>
|
||||
</constructor>
|
||||
|
||||
<destructor>
|
||||
<effects>Destroys a <classname>mutex</classname> object.</effects>
|
||||
|
||||
<requires><code>*this</code> is in an unlocked state.</requires>
|
||||
|
||||
<notes><emphasis role="bold">Danger:</emphasis> Destruction of a
|
||||
locked mutex is a serious programming error resulting in undefined
|
||||
behavior such as a program crash.</notes>
|
||||
</destructor>
|
||||
</class>
|
||||
|
||||
<class name="try_mutex">
|
||||
<purpose>
|
||||
<para>The <classname>try_mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.TryMutex">TryMutex</link> concept.</para>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<para>The <classname>try_mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.TryMutex">TryMutex</link> concept.
|
||||
It should be used to synchronize access to shared resources using
|
||||
<link linkend="thread.concepts.unspecified-locking-strategy">Unspecified</link>
|
||||
locking mechanics.</para>
|
||||
|
||||
<para>For classes that model related mutex concepts, see
|
||||
<classname>mutex</classname> and <classname>timed_mutex</classname>.</para>
|
||||
|
||||
<para>For <link linkend="thread.concepts.recursive-locking-strategy">Recursive</link>
|
||||
locking mechanics, see <classname>recursive_mutex</classname>,
|
||||
<classname>recursive_try_mutex</classname>, and <classname>recursive_timed_mutex</classname>.
|
||||
</para>
|
||||
|
||||
<para>The <classname>try_mutex</classname> class supplies the following typedefs,
|
||||
which <link linkend="thread.concepts.lock-models">model</link>
|
||||
the specified locking strategies:
|
||||
|
||||
<informaltable>
|
||||
<tgroup cols="2" align="left">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Lock Name</entry>
|
||||
<entry>Lock Concept</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>scoped_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedLock">ScopedLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_try_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedTryLock">ScopedTryLock</link></entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
</para>
|
||||
|
||||
<para>The <classname>try_mutex</classname> class uses an
|
||||
<link linkend="thread.concepts.unspecified-locking-strategy">Unspecified</link>
|
||||
locking strategy, so attempts to recursively lock a <classname>try_mutex</classname>
|
||||
object or attempts to unlock one by threads that don't own a lock on it result in
|
||||
<emphasis role="bold">undefined behavior</emphasis>.
|
||||
This strategy allows implementations to be as efficient as possible
|
||||
on any given platform. It is, however, recommended that
|
||||
implementations include debugging support to detect misuse when
|
||||
<code>NDEBUG</code> is not defined.</para>
|
||||
|
||||
<para>Like all
|
||||
<link linkend="thread.concepts.mutex-models">mutex models</link>
|
||||
in &Boost.Thread;, <classname>try_mutex</classname> leaves the
|
||||
<link linkend="thread.concepts.sheduling-policies">scheduling policy</link>
|
||||
as <link linkend="thread.concepts.unspecified-scheduling-policy">Unspecified</link>.
|
||||
Programmers should make no assumptions about the order in which
|
||||
waiting threads acquire a lock.</para>
|
||||
</description>
|
||||
|
||||
<inherit access="private">
|
||||
<type><classname>boost::noncopyable</classname></type>
|
||||
<purpose>Exposition only</purpose>
|
||||
</inherit>
|
||||
|
||||
<typedef name="scoped_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_try_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<constructor>
|
||||
<effects>Constructs a <classname>try_mutex</classname> object.
|
||||
</effects>
|
||||
|
||||
<postconditions><code>*this</code> is in an unlocked state.
|
||||
</postconditions>
|
||||
</constructor>
|
||||
|
||||
<destructor>
|
||||
<effects>Destroys a <classname>try_mutex</classname> object.
|
||||
</effects>
|
||||
|
||||
<requires><code>*this</code> is in an unlocked state.</requires>
|
||||
|
||||
<notes><emphasis role="bold">Danger:</emphasis> Destruction of a
|
||||
locked mutex is a serious programming error resulting in undefined
|
||||
behavior such as a program crash.</notes>
|
||||
</destructor>
|
||||
</class>
|
||||
|
||||
<class name="timed_mutex">
|
||||
<purpose>
|
||||
<para>The <classname>timed_mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.TimedMutex">TimedMutex</link> concept.</para>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<para>The <classname>timed_mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.TimedMutex">TimedMutex</link> concept.
|
||||
It should be used to synchronize access to shared resources using
|
||||
<link linkend="thread.concepts.unspecified-locking-strategy">Unspecified</link>
|
||||
locking mechanics.</para>
|
||||
|
||||
<para>For classes that model related mutex concepts, see
|
||||
<classname>mutex</classname> and <classname>try_mutex</classname>.</para>
|
||||
|
||||
<para>For <link linkend="thread.concepts.recursive-locking-strategy">Recursive</link>
|
||||
locking mechanics, see <classname>recursive_mutex</classname>,
|
||||
<classname>recursive_try_mutex</classname>, and <classname>recursive_timed_mutex</classname>.
|
||||
</para>
|
||||
|
||||
<para>The <classname>timed_mutex</classname> class supplies the following typedefs,
|
||||
which <link linkend="thread.concepts.lock-models">model</link>
|
||||
the specified locking strategies:
|
||||
|
||||
<informaltable>
|
||||
<tgroup cols="2" align="left">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Lock Name</entry>
|
||||
<entry>Lock Concept</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>scoped_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedLock">ScopedLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_try_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedTryLock">ScopedTryLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_timed_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedTimedLock">ScopedTimedLock</link></entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
</para>
|
||||
|
||||
<para>The <classname>timed_mutex</classname> class uses an
|
||||
<link linkend="thread.concepts.unspecified-locking-strategy">Unspecified</link>
|
||||
locking strategy, so attempts to recursively lock a <classname>timed_mutex</classname>
|
||||
object or attempts to unlock one by threads that don't own a lock on it result in
|
||||
<emphasis role="bold">undefined behavior</emphasis>.
|
||||
This strategy allows implementations to be as efficient as possible
|
||||
on any given platform. It is, however, recommended that
|
||||
implementations include debugging support to detect misuse when
|
||||
<code>NDEBUG</code> is not defined.</para>
|
||||
|
||||
<para>Like all
|
||||
<link linkend="thread.concepts.mutex-models">mutex models</link>
|
||||
in &Boost.Thread;, <classname>timed_mutex</classname> leaves the
|
||||
<link linkend="thread.concepts.sheduling-policies">scheduling policy</link>
|
||||
as <link linkend="thread.concepts.unspecified-scheduling-policy">Unspecified</link>.
|
||||
Programmers should make no assumptions about the order in which
|
||||
waiting threads acquire a lock.</para>
|
||||
</description>
|
||||
|
||||
<inherit access="private">
|
||||
<type><classname>boost::noncopyable</classname></type>
|
||||
<purpose>Exposition only</purpose>
|
||||
</inherit>
|
||||
|
||||
<typedef name="scoped_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_try_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_timed_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<constructor>
|
||||
<effects>Constructs a <classname>timed_mutex</classname> object.
|
||||
</effects>
|
||||
|
||||
<postconditions><code>*this</code> is in an unlocked state.
|
||||
</postconditions>
|
||||
</constructor>
|
||||
|
||||
<destructor>
|
||||
<effects>Destroys a <classname>timed_mutex</classname> object.</effects>
|
||||
|
||||
<requires><code>*this</code> is in an unlocked state.</requires>
|
||||
|
||||
<notes><emphasis role="bold">Danger:</emphasis> Destruction of a
|
||||
locked mutex is a serious programming error resulting in undefined
|
||||
behavior such as a program crash.</notes>
|
||||
</destructor>
|
||||
</class>
|
||||
</namespace>
|
||||
</header>
|
||||
3235
doc/mutex_concepts.qbk
Normal file
3235
doc/mutex_concepts.qbk
Normal file
File diff suppressed because it is too large
Load Diff
244
doc/mutexes.qbk
Normal file
244
doc/mutexes.qbk
Normal file
@@ -0,0 +1,244 @@
|
||||
[/
|
||||
(C) Copyright 2007-11 Anthony Williams
|
||||
(C) Copyright 2011-12 Vicente J. Botet Escriba
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:mutex_types Mutex Types]
|
||||
|
||||
[section:mutex Class `mutex`]
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
|
||||
class mutex:
|
||||
boost::noncopyable
|
||||
{
|
||||
public:
|
||||
mutex();
|
||||
~mutex();
|
||||
|
||||
void lock();
|
||||
bool try_lock();
|
||||
void unlock();
|
||||
|
||||
typedef platform-specific-type native_handle_type;
|
||||
native_handle_type native_handle();
|
||||
|
||||
typedef unique_lock<mutex> scoped_lock;
|
||||
typedef unspecified-type scoped_try_lock;
|
||||
};
|
||||
|
||||
__mutex__ implements the __lockable_concept__ to provide an exclusive-ownership mutex. At most one thread can own the lock on a given
|
||||
instance of __mutex__ at any time. Multiple concurrent calls to __lock_ref__, __try_lock_ref__ and __unlock_ref__ shall be permitted.
|
||||
|
||||
[section:nativehandle Member function `native_handle()`]
|
||||
|
||||
typedef platform-specific-type native_handle_type;
|
||||
native_handle_type native_handle();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Returns an instance of `native_handle_type` that can be used with platform-specific APIs to manipulate the underlying
|
||||
implementation. If no such instance exists, `native_handle()` and `native_handle_type` are not present.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:try_mutex Typedef `try_mutex`]
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
|
||||
typedef mutex try_mutex;
|
||||
|
||||
__try_mutex__ is a `typedef` to __mutex__, provided for backwards compatibility with previous releases of boost.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_mutex Class `timed_mutex`]
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
|
||||
class timed_mutex:
|
||||
boost::noncopyable
|
||||
{
|
||||
public:
|
||||
timed_mutex();
|
||||
~timed_mutex();
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
bool try_lock();
|
||||
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& t);
|
||||
|
||||
typedef platform-specific-type native_handle_type;
|
||||
native_handle_type native_handle();
|
||||
|
||||
typedef unique_lock<timed_mutex> scoped_timed_lock;
|
||||
typedef unspecified-type scoped_try_lock;
|
||||
typedef scoped_timed_lock scoped_lock;
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_DATE_TIME || defined BOOST_THREAD_DONT_USE_CHRONO
|
||||
bool timed_lock(system_time const & abs_time);
|
||||
template<typename TimeDuration>
|
||||
bool timed_lock(TimeDuration const & relative_time);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
__timed_mutex__ implements the __timed_lockable_concept__ to provide an exclusive-ownership mutex. At most one thread can own the
|
||||
lock on a given instance of __timed_mutex__ at any time. Multiple concurrent calls to __lock_ref__, __try_lock_ref__,
|
||||
__timed_lock_ref__, __timed_lock_duration_ref__ and __unlock_ref__ shall be permitted.
|
||||
|
||||
[section:nativehandle Member function `native_handle()`]
|
||||
|
||||
typedef platform-specific-type native_handle_type;
|
||||
native_handle_type native_handle();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Returns an instance of `native_handle_type` that can be used with platform-specific APIs to manipulate the underlying
|
||||
implementation. If no such instance exists, `native_handle()` and `native_handle_type` are not present.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:recursive_mutex Class `recursive_mutex`]
|
||||
|
||||
#include <boost/thread/recursive_mutex.hpp>
|
||||
|
||||
class recursive_mutex:
|
||||
boost::noncopyable
|
||||
{
|
||||
public:
|
||||
recursive_mutex();
|
||||
~recursive_mutex();
|
||||
|
||||
void lock();
|
||||
bool try_lock() noexcept;
|
||||
void unlock();
|
||||
|
||||
typedef platform-specific-type native_handle_type;
|
||||
native_handle_type native_handle();
|
||||
|
||||
typedef unique_lock<recursive_mutex> scoped_lock;
|
||||
typedef unspecified-type scoped_try_lock;
|
||||
};
|
||||
|
||||
__recursive_mutex__ implements the __lockable_concept__ to provide an exclusive-ownership recursive mutex. At most one thread can
|
||||
own the lock on a given instance of __recursive_mutex__ at any time. Multiple concurrent calls to __lock_ref__, __try_lock_ref__ and
|
||||
__unlock_ref__ shall be permitted. A thread that already has exclusive ownership of a given __recursive_mutex__ instance can call
|
||||
__lock_ref__ or __try_lock_ref__ to acquire an additional level of ownership of the mutex. __unlock_ref__ must be called once for
|
||||
each level of ownership acquired by a single thread before ownership can be acquired by another thread.
|
||||
|
||||
[section:nativehandle Member function `native_handle()`]
|
||||
|
||||
typedef platform-specific-type native_handle_type;
|
||||
native_handle_type native_handle();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Returns an instance of `native_handle_type` that can be used with platform-specific APIs to manipulate the underlying
|
||||
implementation. If no such instance exists, `native_handle()` and `native_handle_type` are not present.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:recursive_try_mutex Typedef `recursive_try_mutex`]
|
||||
|
||||
#include <boost/thread/recursive_mutex.hpp>
|
||||
|
||||
typedef recursive_mutex recursive_try_mutex;
|
||||
|
||||
__recursive_try_mutex__ is a `typedef` to __recursive_mutex__, provided for backwards compatibility with previous releases of boost.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:recursive_timed_mutex Class `recursive_timed_mutex`]
|
||||
|
||||
#include <boost/thread/recursive_mutex.hpp>
|
||||
|
||||
class recursive_timed_mutex:
|
||||
boost::noncopyable
|
||||
{
|
||||
public:
|
||||
recursive_timed_mutex();
|
||||
~recursive_timed_mutex();
|
||||
|
||||
void lock();
|
||||
bool try_lock() noexcept;
|
||||
void unlock();
|
||||
|
||||
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& t);
|
||||
|
||||
typedef platform-specific-type native_handle_type;
|
||||
native_handle_type native_handle();
|
||||
|
||||
typedef unique_lock<recursive_timed_mutex> scoped_lock;
|
||||
typedef unspecified-type scoped_try_lock;
|
||||
typedef scoped_lock scoped_timed_lock;
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_DATE_TIME || defined BOOST_THREAD_DONT_USE_CHRONO
|
||||
bool timed_lock(system_time const & abs_time);
|
||||
template<typename TimeDuration>
|
||||
bool timed_lock(TimeDuration const & relative_time);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
__recursive_timed_mutex__ implements the __timed_lockable_concept__ to provide an exclusive-ownership recursive mutex. At most one
|
||||
thread can own the lock on a given instance of __recursive_timed_mutex__ at any time. Multiple concurrent calls to __lock_ref__,
|
||||
__try_lock_ref__, __timed_lock_ref__, __timed_lock_duration_ref__ and __unlock_ref__ shall be permitted. A thread that already has
|
||||
exclusive ownership of a given __recursive_timed_mutex__ instance can call __lock_ref__, __timed_lock_ref__,
|
||||
__timed_lock_duration_ref__ or __try_lock_ref__ to acquire an additional level of ownership of the mutex. __unlock_ref__ must be
|
||||
called once for each level of ownership acquired by a single thread before ownership can be acquired by another thread.
|
||||
|
||||
[section:nativehandle Member function `native_handle()`]
|
||||
|
||||
typedef platform-specific-type native_handle_type;
|
||||
native_handle_type native_handle();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Returns an instance of `native_handle_type` that can be used with platform-specific APIs to manipulate the underlying
|
||||
implementation. If no such instance exists, `native_handle()` and `native_handle_type` are not present.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[include shared_mutex_ref.qbk]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/once.hpp"
|
||||
last-revision="$Date$">
|
||||
<macro name="BOOST_ONCE_INIT">
|
||||
<purpose>The <functionname>call_once</functionname> function and
|
||||
<code>once_flag</code> type (statically initialized to
|
||||
<macroname>BOOST_ONCE_INIT</macroname>) can be used to run a
|
||||
routine exactly once. This can be used to initialize data in a
|
||||
<link linkend="thread.glossary.thread-safe">thread-safe</link>
|
||||
manner.</purpose>
|
||||
|
||||
<description>The implementation-defined macro
|
||||
<macroname>BOOST_ONCE_INIT</macroname> is a constant value used to
|
||||
initialize <code>once_flag</code> instances to indicate that the
|
||||
logically associated routine has not been run yet. See
|
||||
<functionname>call_once</functionname> for more details.</description>
|
||||
</macro>
|
||||
|
||||
<namespace name="boost">
|
||||
<typedef name="once_flag">
|
||||
<purpose>The <functionname>call_once</functionname> function and
|
||||
<code>once_flag</code> type (statically initialized to
|
||||
<macroname>BOOST_ONCE_INIT</macroname>) can be used to run a
|
||||
routine exactly once. This can be used to initialize data in a
|
||||
<link linkend="thread.glossary.thread-safe">thread-safe</link>
|
||||
manner.</purpose>
|
||||
|
||||
<description>The implementation-defined type <code>once_flag</code>
|
||||
is used as a flag to insure a routine is called only once.
|
||||
Instances of this type should be statically initialized to
|
||||
<macroname>BOOST_ONCE_INIT</macroname>. See
|
||||
<functionname>call_once</functionname> for more details.
|
||||
</description>
|
||||
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<function name="call_once">
|
||||
<purpose>The <functionname>call_once</functionname> function and
|
||||
<code>once_flag</code> type (statically initialized to
|
||||
<macroname>BOOST_ONCE_INIT</macroname>) can be used to run a
|
||||
routine exactly once. This can be used to initialize data in a
|
||||
<link linkend="thread.glossary.thread-safe">thread-safe</link>
|
||||
manner.</purpose>
|
||||
|
||||
<description>
|
||||
<para>Example usage is as follows:</para>
|
||||
<para>
|
||||
<programlisting>//Example usage:
|
||||
boost::once_flag once = BOOST_ONCE_INIT;
|
||||
|
||||
void init()
|
||||
{
|
||||
//...
|
||||
}
|
||||
|
||||
void thread_proc()
|
||||
{
|
||||
boost::call_once(&init, once);
|
||||
}</programlisting>
|
||||
</para></description>
|
||||
|
||||
<parameter name="func">
|
||||
<paramtype>void (*func)()</paramtype>
|
||||
</parameter>
|
||||
|
||||
<parameter name="flag">
|
||||
<paramtype>once_flag&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<requires>The function <code>func</code> shall not throw
|
||||
exceptions.</requires>
|
||||
|
||||
<effects>As if (in an atomic fashion):
|
||||
<code>if (flag == BOOST_ONCE_INIT) func();</code></effects>
|
||||
|
||||
<postconditions><code>flag != BOOST_ONCE_INIT</code>
|
||||
</postconditions>
|
||||
</function>
|
||||
</namespace>
|
||||
</header>
|
||||
90
doc/once.qbk
Normal file
90
doc/once.qbk
Normal file
@@ -0,0 +1,90 @@
|
||||
[/
|
||||
(C) Copyright 2007-8 Anthony Williams.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:once One-time Initialization]
|
||||
|
||||
#include <boost/thread/once.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
struct once_flag;
|
||||
template<typename Function, class ...ArgTypes>
|
||||
inline void call_once(once_flag& flag, Function&& f, ArgTypes&&... args);
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_DEPRECATED_FEATURES_SINCE_V3_0_0
|
||||
void call_once(void (*func)(),once_flag& flag);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
[warning the variadic prototype is provided only on C++11 compilers supporting variadic templates, otherwise the interface is limited up to 3 parameters.]
|
||||
|
||||
[warning the move semantics is ensured only on C++11 compilers supporting SFINAE expression, decltype N3276 and auto. Waiting for a boost::bind that is move aware.]
|
||||
|
||||
|
||||
`boost::call_once` provides a mechanism for ensuring that an initialization routine is run exactly once without data races or deadlocks.
|
||||
|
||||
[section:once_flag Typedef `once_flag`]
|
||||
|
||||
#ifdef BOOST_THREAD_PROVIDES_ONCE_CXX11
|
||||
struct once_flag
|
||||
{
|
||||
constexprr once_flag() noexcept;
|
||||
once_flag(const once_flag&) = delete;
|
||||
once_flag& operator=(const once_flag&) = delete;
|
||||
};
|
||||
#else
|
||||
typedef platform-specific-type once_flag;
|
||||
#define BOOST_ONCE_INIT platform-specific-initializer
|
||||
#endif
|
||||
|
||||
Objects of type `boost::once_flag` shall be initialized with `BOOST_ONCE_INIT` if BOOST_THREAD_PROVIDES_ONCE_CXX11 is not defined
|
||||
|
||||
boost::once_flag f=BOOST_ONCE_INIT;
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:call_once Non-member function `call_once`]
|
||||
|
||||
template<typename Function, class ...ArgTypes>
|
||||
inline void call_once(once_flag& flag, Function&& f, ArgTypes&&... args);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`Function` and each or the `ArgTypes` are `MoveConstructible` and `invoke(decay_copy(boost::forward<Function>(f)), decay_copy(boost::forward<ArgTypes>(args))...)` shall be well formed. ]]
|
||||
|
||||
[[Effects:] [Calls to `call_once` on the same `once_flag` object are serialized. If there has been no prior effective `call_once` on
|
||||
the same `once_flag` object, the argument `func` is called as-if by invoking `invoke(decay_copy(boost::forward<Function>(f)), decay_copy(boost::forward<ArgTypes>(args))...)`, and the invocation of
|
||||
`call_once` is effective if and only if `invoke(decay_copy(boost::forward<Function>(f)), decay_copy(boost::forward<ArgTypes>(args))...)` returns without exception. If an exception is thrown, the exception is propagated to the caller. If there has been a prior effective `call_once` on the same `once_flag` object, the `call_once` returns
|
||||
without invoking `func`. ]]
|
||||
|
||||
[[Synchronization:] [The completion of an effective `call_once` invocation on a `once_flag` object, synchronizes with
|
||||
all subsequent `call_once` invocations on the same `once_flag` object. ]]
|
||||
|
||||
[[Throws:] [`thread_resource_error` when the effects cannot be achieved or any exception propagated from `func`.]]
|
||||
|
||||
[[Note:] [The function passed to `call_once` must not also call
|
||||
`call_once` passing the same `once_flag` object. This may cause
|
||||
deadlock, or invoking the passed function a second time. The
|
||||
alternative is to allow the second call to return immediately, but
|
||||
that assumes the code knows it has been called recursively, and can
|
||||
proceed even though the call to `call_once` didn't actually call the
|
||||
function, in which case it could also avoid calling `call_once`
|
||||
recursively.]]
|
||||
|
||||
|
||||
[[Note:] [On some compilers this function has some restrictions, e.g. if variadic templates are not supported the number of arguments is limited to 3; .]]
|
||||
|
||||
]
|
||||
|
||||
void call_once(void (*func)(),once_flag& flag);
|
||||
|
||||
This second overload is provided for backwards compatibility and is deprecated. The effects of `call_once(func,flag)` shall be the same as those of
|
||||
`call_once(flag,func)`.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
74
doc/overview.qbk
Normal file
74
doc/overview.qbk
Normal file
@@ -0,0 +1,74 @@
|
||||
[/
|
||||
(C) Copyright 2007-12 Anthony Williams.
|
||||
(C) Copyright 20012 Vicente J. Botet Escriba.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:overview Overview]
|
||||
|
||||
__boost_thread__ enables the use of multiple threads of execution with shared data in portable C++ code. It provides classes and
|
||||
functions for managing the threads themselves, along with others for synchronizing data between the threads or providing separate
|
||||
copies of data specific to individual threads.
|
||||
|
||||
The __boost_thread__ library was originally written and designed by William E. Kempf (version 1).
|
||||
|
||||
Anthony Williams version (version 2) was a major rewrite designed to
|
||||
closely follow the proposals presented to the C++ Standards Committee, in particular
|
||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html N2497],
|
||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2320.html N2320],
|
||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2184.html N2184],
|
||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2139.html N2139], and
|
||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2094.html N2094]
|
||||
|
||||
Vicente J. Botet Escriba started (version 3) the adaptation to comply with the accepted Thread C++11 library (Make use of Boost.Chrono and Boost.Move) and the [@http://home.roadrunner.com/~hinnant/bloomington/shared_mutex.html Shared Locking] Howard Hinnant proposal except for the upward conversions.
|
||||
Some minor non-standard features have been added also as thread attributes, reverse_lock, shared_lock_guard.
|
||||
|
||||
In order to use the classes and functions described here, you can
|
||||
either include the specific headers specified by the descriptions of
|
||||
each class or function, or include the master thread library header:
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
which includes all the other headers in turn.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:build Using and building the library]
|
||||
|
||||
Boost.Thread is configured following the conventions used to build [@http://www.boost.org/doc/libs/1_48_0/libs/config/doc/html/boost_config/boost_macro_reference.html#boost_config.boost_macro_reference.macros_for_libraries_with_separate_source_code libraries with separate source code]. Boost.Thread will import/export the code only if the user has specifically asked for it, by defining either BOOST_ALL_DYN_LINK if they want all boost libraries to be dynamically linked, or BOOST_THREAD_DYN_LINK if they want just this one to be dynamically liked.
|
||||
|
||||
The definition of these macros determines whether BOOST_THREAD_USE_DLL is defined. If BOOST_THREAD_USE_DLL is not defined, the library will define BOOST_THREAD_USE_DLL or BOOST_THREAD_USE_LIB depending on whether the platform. On non windows platforms BOOST_THREAD_USE_LIB is defined if is not defined. In windows platforms, BOOST_THREAD_USE_LIB is defined if BOOST_THREAD_USE_DLL and the compiler supports auto-tss cleanup with Boost.Threads (for the time been Msvc and Intel)
|
||||
|
||||
The source code compiled when building the library defines a macros BOOST_THREAD_SOURCE that is used to import or export it. The user must not define this macro in any case.
|
||||
|
||||
Boost.Thread depends on some non header-only libraries.
|
||||
|
||||
* Boost.System: This dependency is mandatory and you will need to link with the library.
|
||||
|
||||
* Boost.Chrono: This dependency is optional (see below how to configure) and you will need to link with the library if you use some of the time related interfaces.
|
||||
|
||||
* Boost.DateTime: This dependency is mandatory, but even if Boost.DateTime is a non header-only library Boost.Thread uses only parts that are header-only, so in principle you should not need to link with the library.
|
||||
|
||||
It seems that there are some IDE (as e.g. Visual Studio) that deduce the libraries that a program needs to link to inspecting the sources. Such IDE could force to link to Boost.DateTime and/or Boost.Chrono.
|
||||
|
||||
As the single mandatory dependency is to Boost.System, the following
|
||||
|
||||
bjam toolset=msvc-11.0 --build-type=complete --with-thread
|
||||
|
||||
will install only boost_thread and boost_system.
|
||||
|
||||
Users of such IDE should force the Boost.Chrono and Boost.DateTime build using
|
||||
|
||||
bjam toolset=msvc-11.0 --build-type=complete --with-thread --with-chrono --with-date_time
|
||||
|
||||
|
||||
The following section describes all the macros used to configure Boost.Thread.
|
||||
|
||||
[include configuration.qbk]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
206
doc/overview.xml
206
doc/overview.xml
@@ -1,206 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.overview" last-revision="$Date$">
|
||||
<title>Overview</title>
|
||||
<section id="thread.introduction">
|
||||
<title>Introduction</title>
|
||||
<para>&Boost.Thread; allows C++ programs to execute as multiple,
|
||||
asynchronous, independent threads-of-execution. Each thread has its own
|
||||
machine state including program instruction counter and registers. Programs
|
||||
which execute as multiple threads are called multithreaded programs to
|
||||
distinguish them from traditional single-threaded programs. The <link
|
||||
linkend="thread.glossary">glossary</link> gives a more complete description
|
||||
of the multithreading execution environment.</para>
|
||||
<para>Multithreading provides several advantages:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>Programs which would otherwise block waiting for some external
|
||||
event can continue to respond if the blocking operation is placed in a
|
||||
separate thread. Multithreading is usually an absolute requirement for
|
||||
these programs.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Well-designed multithreaded programs may execute faster than
|
||||
single-threaded programs, particularly on multiprocessor hardware.
|
||||
Note, however, that poorly-designed multithreaded programs are often
|
||||
slower than single-threaded programs.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Some program designs may be easier to formulate using a
|
||||
multithreaded approach. After all, the real world is
|
||||
asynchronous!</para>
|
||||
</listitem>
|
||||
</itemizedlist></para>
|
||||
</section>
|
||||
<section>
|
||||
<title>Dangers</title>
|
||||
<section>
|
||||
<title>General considerations</title>
|
||||
<para>Beyond the errors which can occur in single-threaded programs,
|
||||
multithreaded programs are subject to additional errors:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para><link linkend="thread.glossary.race-condition">Race
|
||||
conditions</link></para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><link linkend="thread.glossary.deadlock">Deadlock</link>
|
||||
(sometimes called "deadly embrace")</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><link linkend="thread.glossary.priority-failure">Priority
|
||||
failures</link> (priority inversion, infinite overtaking, starvation,
|
||||
etc.)</para>
|
||||
</listitem>
|
||||
</itemizedlist></para>
|
||||
<para>Every multithreaded program must be designed carefully to avoid these
|
||||
errors. These aren't rare or exotic failures - they are virtually guaranteed
|
||||
to occur unless multithreaded code is designed to avoid them. Priority
|
||||
failures are somewhat less common, but are nonetheless serious.</para>
|
||||
<para>The <link linkend="thread.design">&Boost.Thread; design</link>
|
||||
attempts to minimize these errors, but they will still occur unless the
|
||||
programmer proactively designs to avoid them.</para>
|
||||
<note>Please also see <xref linkend="thread.implementation_notes"/>
|
||||
for additional, implementation-specific considerations.</note>
|
||||
</section>
|
||||
<section>
|
||||
<title>Testing and debugging considerations</title>
|
||||
<para>Multithreaded programs are non-deterministic. In other words, the
|
||||
same program with the same input data may follow different execution
|
||||
paths each time it is invoked. That can make testing and debugging a
|
||||
nightmare:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>Failures are often not repeatable.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Probe effect causes debuggers to produce very different results
|
||||
from non-debug uses.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Debuggers require special support to show thread state.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>Tests on a single processor system may give no indication of
|
||||
serious errors which would appear on multiprocessor systems, and visa
|
||||
versa. Thus test cases should include a varying number of
|
||||
processors.</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>For programs which create a varying number of threads according
|
||||
to workload, tests which don't span the full range of possibilities
|
||||
may miss serious errors.</para>
|
||||
</listitem>
|
||||
</itemizedlist></para>
|
||||
</section>
|
||||
<section>
|
||||
<title>Getting a head start</title>
|
||||
<para>Although it might appear that multithreaded programs are inherently
|
||||
unreliable, many reliable multithreaded programs do exist. Multithreading
|
||||
techniques are known which lead to reliable programs.</para>
|
||||
<para>Design patterns for reliable multithreaded programs, including the
|
||||
important <emphasis>monitor</emphasis> pattern, are presented in
|
||||
<emphasis>Pattern-Oriented Software Architecture Volume 2 - Patterns for
|
||||
Concurrent and Networked Objects</emphasis>
|
||||
&cite.SchmidtStalRohnertBuschmann;. Many important multithreading programming
|
||||
considerations (independent of threading library) are discussed in
|
||||
<emphasis>Programming with POSIX Threads</emphasis> &cite.Butenhof97;.</para>
|
||||
<para>Doing some reading before attempting multithreaded designs will
|
||||
give you a head start toward reliable multithreaded programs.</para>
|
||||
</section>
|
||||
</section>
|
||||
<section>
|
||||
<title>C++ Standard Library usage in multithreaded programs</title>
|
||||
<section>
|
||||
<title>Runtime libraries</title>
|
||||
<para>
|
||||
<emphasis role="bold">Warning:</emphasis> Multithreaded programs such as
|
||||
those using &Boost.Thread; must link to <link
|
||||
linkend="thread.glossary.thread-safe">thread-safe</link> versions of
|
||||
all runtime libraries used by the program, including the runtime library
|
||||
for the C++ Standard Library. Failure to do so will cause <link
|
||||
linkend="thread.glossary.race-condition">race conditions</link> to occur
|
||||
when multiple threads simultaneously execute runtime library functions for
|
||||
<code>new</code>, <code>delete</code>, or other language features which
|
||||
imply shared state.</para>
|
||||
</section>
|
||||
<section>
|
||||
<title>Potentially non-thread-safe functions</title>
|
||||
<para>Certain C++ Standard Library functions inherited from C are
|
||||
particular problems because they hold internal state between
|
||||
calls:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para><code>rand</code></para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><code>strtok</code></para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><code>asctime</code></para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><code>ctime</code></para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><code>gmtime</code></para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><code>localtime</code></para>
|
||||
</listitem>
|
||||
</itemizedlist></para>
|
||||
<para>It is possible to write thread-safe implementations of these by
|
||||
using thread specific storage (see
|
||||
<classname>boost::thread_specific_ptr</classname>), and several C++
|
||||
compiler vendors do just that. The technique is well-know and is explained
|
||||
in &cite.Butenhof97;.</para>
|
||||
<para>But at least one vendor (HP-UX) does not provide thread-safe
|
||||
implementations of the above functions in their otherwise thread-safe
|
||||
runtime library. Instead they provide replacement functions with
|
||||
different names and arguments.</para>
|
||||
<para><emphasis role="bold">Recommendation:</emphasis> For the most
|
||||
portable, yet thread-safe code, use Boost replacements for the problem
|
||||
functions. See the <libraryname>Boost Random Number Library</libraryname>
|
||||
and <libraryname>Boost Tokenizer Library</libraryname>.</para>
|
||||
</section>
|
||||
</section>
|
||||
<section>
|
||||
<title>Common guarantees for all &Boost.Thread; components</title>
|
||||
<section>
|
||||
<title>Exceptions</title>
|
||||
<para>&Boost.Thread; destructors never
|
||||
throw exceptions. Unless otherwise specified, other
|
||||
&Boost.Thread; functions that do not have
|
||||
an exception-specification may throw implementation-defined
|
||||
exceptions.</para>
|
||||
<para>In particular, &Boost.Thread;
|
||||
reports failure to allocate storage by throwing an exception of type
|
||||
<code>std::bad_alloc</code> or a class derived from
|
||||
<code>std::bad_alloc</code>, failure to obtain thread resources other than
|
||||
memory by throwing an exception of type
|
||||
<classname>boost::thread_resource_error</classname>, and certain lock
|
||||
related failures by throwing an exception of type
|
||||
<classname>boost::lock_error</classname>.</para>
|
||||
<para><emphasis role="bold">Rationale:</emphasis> Follows the C++ Standard
|
||||
Library practice of allowing all functions except destructors or other
|
||||
specified functions to throw exceptions on errors.</para>
|
||||
</section>
|
||||
<section>
|
||||
<title>NonCopyable requirement</title>
|
||||
<para>&Boost.Thread; classes documented as
|
||||
meeting the NonCopyable requirement disallow copy construction and copy
|
||||
assignment. For the sake of exposition, the synopsis of such classes show
|
||||
private derivation from <classname>boost::noncopyable</classname>. Users
|
||||
should not depend on this derivation, however, as implementations are free
|
||||
to meet the NonCopyable requirement in other ways.</para>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
482
doc/parallel.qbk
Normal file
482
doc/parallel.qbk
Normal file
@@ -0,0 +1,482 @@
|
||||
[/
|
||||
/ Copyright (c) 2014 Vicente J. Botet Escriba
|
||||
/
|
||||
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
|
||||
[//////////////////////////////////////////////////////////]
|
||||
[section:parallel Parallel - Fork-Join -- EXPERIMENTAL]
|
||||
|
||||
[section:fork_join Fork-Join]
|
||||
|
||||
[warning These features are experimental and subject to change in future versions. There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
|
||||
|
||||
[note These features are based on the [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4088.pdf [* n4088 - Task Region R3]] C++1y proposal from P. Halpern, A. Robison, A. Laksberg, H. Sutter, et al. The text that follows has been adapted from this paper to show the differences.]
|
||||
|
||||
The major difference respect to the standard proposal is that we are able to use a common executor for several task regions.
|
||||
|
||||
[note
|
||||
Up to now, Boost.Thread doesn't implement the parallel algorithms as defined in [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4105.pdf [* n4105 - Information technology – Programming languages, their environments and system software interfaces – Technical Specification for C++ Extensions for Parallelism]].
|
||||
]
|
||||
|
||||
[////////////////////]
|
||||
[section Introduction]
|
||||
|
||||
|
||||
This module introduces a C++11/c++14 library function template `task_region` and a library class `task_region_handle`
|
||||
with member functions `run` and `wait` that together enable developers to write expressive and portable fork-join
|
||||
parallel code.
|
||||
|
||||
The working draft for the Parallelism TS [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4105.pdf [*N4105]] augments the STL algorithms with the inclusion of parallel execution policies. Programmers use these as a basis to write additional high-level algorithms that can be implemented in terms of the provided parallel algorithms. However, the scope of n4105 does not include lower-level mechanisms to express arbitrary fork-join parallelism
|
||||
|
||||
The `task_region`, `run` and the `wait` functions provided by this library are based on the `task_group` concept that is a part of the common subset of the PPL and the TBB libraries.
|
||||
|
||||
[endsect] [/ Introduction]
|
||||
|
||||
|
||||
[/////////////////////////]
|
||||
[section:tutorial Tutorial]
|
||||
|
||||
Consider an example of a parallel traversal of a tree, where a user-provided function compute is applied to each node of the tree, returning the sum of the results:
|
||||
|
||||
template<typename Func>
|
||||
int traverse(node *n, Func&& compute)
|
||||
{
|
||||
int left = 0, right = 0;
|
||||
task_region([&](task_region_handle& tr) {
|
||||
if (n->left)
|
||||
tr.run([&] { left = traverse(n->left, compute); });
|
||||
if (n->right)
|
||||
tr.run([&] { right = traverse(n->right, compute); });
|
||||
});
|
||||
return compute(n) + left + right;
|
||||
}
|
||||
|
||||
The example above demonstrates the use of two of the functions proposed in this paper, `task_region` and
|
||||
`task_region_handle::run`.
|
||||
The `task_region` function delineates a region in a program code potentially containing invocations of tasks
|
||||
spawned by the `run` member function of the `task_region_handle` class.
|
||||
|
||||
The run function spawns a task, a unit of work that is allowed to execute in parallel with respect to the caller.
|
||||
Any parallel tasks spawned by `run` within the `task_region` are joined back to a single thread of execution at
|
||||
the end of the `task_region`.
|
||||
|
||||
`run` takes a user-provided function object `f` and starts it asynchronously - i.e. it may return before the
|
||||
execution of `f` completes. The implementation's scheduler may choose to run `f` immediately or delay running
|
||||
`f` until compute resources become available.
|
||||
|
||||
A `task_region_handle` can be constructed only by `task_region` because it has no public constructors.
|
||||
Thus, `run` can be invoked (directly or indirectly) only from a user-provided function passed to `task_region`:
|
||||
|
||||
void g();
|
||||
void f(task_region_handle& tr)
|
||||
{
|
||||
tr.run(g); // OK, invoked from within task_region in h
|
||||
}
|
||||
void h()
|
||||
{
|
||||
task_region(f);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
task_region_handle tr; // Error: no public constructor
|
||||
tr.run(g); // No way to call run outside of a task_region
|
||||
return 0;
|
||||
}
|
||||
|
||||
[endsect] [/ Tutorial]
|
||||
|
||||
[////////////////]
|
||||
[section:examples Examples]
|
||||
|
||||
[section:fib Parallel Fibonacci]
|
||||
|
||||
|
||||
This is surely the worst implementation of the Fibonacci function. Anyway, here it is, as it is simple and shows the fork-join structure clearly. `Fibonacci(n) = Fibonacci(n-1) + Fibonacci(n-2)`, so the task decomposition is trivial.
|
||||
|
||||
int fib_task_region(int n)
|
||||
{
|
||||
using boost::experimental::parallel::task_region;
|
||||
using boost::experimental::parallel::task_region_handle;
|
||||
|
||||
if (n == 0) return 0;
|
||||
if (n == 1) return 1;
|
||||
|
||||
int n1;
|
||||
int n2;
|
||||
|
||||
task_region([&](task_region_handle& trh)
|
||||
{
|
||||
trh.run([&]
|
||||
{
|
||||
n1 = fib_task_region(n - 1);
|
||||
});
|
||||
|
||||
n2 = fib_task_region(n - 2);
|
||||
});
|
||||
|
||||
return n1 + n2;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
for (int i = 0; i<10; ++i) {
|
||||
std::cout << fib_task_region(i) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
[endsect] [/ Fib]
|
||||
[section:fibex Parallel Fibonacci - Specific executor]
|
||||
|
||||
The previous example make use of an implementation defined way to spawn the tasks. Often the user wants to master how the task must be spawned. There is an overload of `task_region` that accept an additional `Executor` parameter and a function that takes as parameter a `task_region_handle_gen<Executor>`. `task_region_handle_gen<Executor>` run uses this executor to spawn the tasks.
|
||||
|
||||
template <class Ex>
|
||||
int fib_task_region_gen( Ex& ex, int n)
|
||||
{
|
||||
using boost::experimental::parallel::task_region;
|
||||
using boost::experimental::parallel::task_region_handle_gen;
|
||||
|
||||
if (n == 0) return 0;
|
||||
if (n == 1) return 1;
|
||||
|
||||
int n1;
|
||||
int n2;
|
||||
|
||||
task_region(ex, [&](task_region_handle_gen<Ex>& trh) // (2)
|
||||
{
|
||||
trh.run([&]
|
||||
{
|
||||
n1 = fib_task_region(n - 1);
|
||||
});
|
||||
|
||||
n2 = fib_task_region(n - 2);
|
||||
});
|
||||
|
||||
return n1 + n2;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::basic_thread_pool tp; // (1)
|
||||
for (int i = 0; i<10; ++i) {
|
||||
std::cout << fib_task_region_gen(tp,i) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
The specific executor is declared in line (1) and it is used in line (2).
|
||||
|
||||
[endsect] [/ Fib ex]
|
||||
|
||||
|
||||
|
||||
|
||||
[section:quick_sort Parallel Accumulate]
|
||||
|
||||
|
||||
[endsect] [/ Accumulate]
|
||||
|
||||
[section:quick_sort Parallel Quick Sort]
|
||||
|
||||
|
||||
|
||||
[endsect] [/ QuickSort]
|
||||
[endsect] [/ Examples]
|
||||
|
||||
|
||||
[////////////////////////]
|
||||
[section:rationale Design Rationale]
|
||||
|
||||
|
||||
[endsect] [/ Design Rationale]
|
||||
[endsect] [/ Fork-Join]
|
||||
|
||||
[/////////////////////]
|
||||
[section:ref Reference -- EXPERIMENTAL]
|
||||
|
||||
[/////////////////////////]
|
||||
[section:v1 Parallel V1]
|
||||
|
||||
[section:exception_list Header `<experimental/exception_list.hpp>`]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v1
|
||||
{
|
||||
|
||||
class exception_list;
|
||||
|
||||
} // v1
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
|
||||
[/////////////////////////]
|
||||
[section:exception_list Class `exception_list`]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v1
|
||||
{
|
||||
|
||||
class exception_list: public std::exception
|
||||
{
|
||||
public:
|
||||
typedef 'implementation defined' const_iterator;
|
||||
|
||||
~exception_list() noexcept {}
|
||||
|
||||
void add(exception_ptr const& e);
|
||||
size_t size() const noexcept;
|
||||
const_iterator begin() const noexcept;
|
||||
const_iterator end() const noexcept;
|
||||
const char* what() const noexcept;
|
||||
|
||||
};
|
||||
|
||||
} // v1
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
|
||||
[endsect] [/ exception_list]
|
||||
|
||||
[endsect] [/ exception_list.hpp]
|
||||
|
||||
[endsect] [/ Parallel V1]
|
||||
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:v2 Parallel V2]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:concepts Concepts]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:regionCallable Concept `Region_Callable`]
|
||||
|
||||
[endsect] [/ Region_Callable]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:taskCallable Concept `Task_Callable`]
|
||||
|
||||
|
||||
[endsect] [/ Task_Callable]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[endsect] [/ Concepts]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:task_region Header `<experimental/task_region.hpp>`]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v2
|
||||
{
|
||||
|
||||
class task_canceled_exception;
|
||||
|
||||
template <class Executor>
|
||||
class task_region_handle_gen;
|
||||
|
||||
using default_executor = 'implementation defined';
|
||||
|
||||
class task_region_handle;
|
||||
|
||||
template <typename Executor, typename F>
|
||||
void task_region_final(Executor& ex, F&& f);
|
||||
template <typename F>
|
||||
void task_region_final(F&& f);
|
||||
|
||||
template <typename Executor, typename F>
|
||||
void task_region(Executor& ex, F&& f);
|
||||
template <typename F>
|
||||
void task_region(F&& f);
|
||||
|
||||
} // v2
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:task_canceled_exception Class `task_canceled_exception `]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v2
|
||||
{
|
||||
|
||||
class task_canceled_exception: public std::exception
|
||||
{
|
||||
public:
|
||||
task_canceled_exception() noexcept;
|
||||
task_canceled_exception(const task_canceled_exception&) noexcept;
|
||||
task_canceled_exception& operator=(const task_canceled_exception&) noexcept;
|
||||
virtual const char* what() const noexcept;
|
||||
};
|
||||
|
||||
} // v2
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
[endsect] [/ task_canceled_exception]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:task_region_handle_gen Template Class `task_region_handle_gen<>`]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v2
|
||||
{
|
||||
|
||||
template <class Executor>
|
||||
class task_region_handle_gen
|
||||
{
|
||||
protected:
|
||||
task_region_handle_gen(Executor& ex);
|
||||
|
||||
~task_region_handle_gen();
|
||||
|
||||
public:
|
||||
task_region_handle_gen(const task_region_handle_gen&) = delete;
|
||||
task_region_handle_gen& operator=(const task_region_handle_gen&) = delete;
|
||||
task_region_handle_gen* operator&() const = delete;
|
||||
|
||||
template<typename F>
|
||||
void run(F&& f);
|
||||
|
||||
void wait();
|
||||
};
|
||||
|
||||
} // v2
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
[endsect] [/ task_region_handle_gen]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:default_executor Class `default_executor `]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v2
|
||||
{
|
||||
|
||||
using default_executor = 'implementation defined';
|
||||
|
||||
} // v2
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
[endsect] [/ default_executor]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:task_region_handle Class `task_region_handle `]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v2
|
||||
{
|
||||
|
||||
class task_region_handle :
|
||||
public task_region_handle_gen<default_executor>
|
||||
{
|
||||
protected:
|
||||
task_region_handle();
|
||||
task_region_handle(const task_region_handle&) = delete;
|
||||
task_region_handle& operator=(const task_region_handle&) = delete;
|
||||
task_region_handle* operator&() const = delete;
|
||||
|
||||
};
|
||||
|
||||
} // v2
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
[endsect] [/ task_region_handle]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:task_region_final Template Function `task_region_final `]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v2
|
||||
{
|
||||
|
||||
template <typename Executor, typename F>
|
||||
void task_region_final(Executor& ex, F&& f);
|
||||
template <typename F>
|
||||
void task_region_final(F&& f);
|
||||
|
||||
} // v2
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
[endsect] [/ task_region_final]
|
||||
[////////////////////////////////////////////////////////////////////]
|
||||
[section:task_region Template Function `task_region `]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace experimental
|
||||
{
|
||||
namespace parallel
|
||||
{
|
||||
inline namespace v2
|
||||
{
|
||||
|
||||
template <typename Executor, typename F>
|
||||
void task_region(Executor& ex, F&& f);
|
||||
template <typename F>
|
||||
void task_region(F&& f);
|
||||
|
||||
} // v2
|
||||
} // parallel
|
||||
} // experimental
|
||||
} // boost
|
||||
|
||||
[endsect] [/ task_region]
|
||||
|
||||
|
||||
|
||||
|
||||
[endsect] [/ task_region.hpp]
|
||||
[endsect] [/ Parallel V2]
|
||||
[endsect] [/ Reference]
|
||||
|
||||
[endsect] [/ Parallel]
|
||||
@@ -1,438 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.rationale" last-revision="$Date$">
|
||||
<title>Rationale</title>
|
||||
<para>This page explains the rationale behind various design decisions in the
|
||||
&Boost.Thread; library. Having the rationale documented here should explain
|
||||
how we arrived at the current design as well as prevent future rehashing of
|
||||
discussions and thought processes that have already occurred. It can also give
|
||||
users a lot of insight into the design process required for this
|
||||
library.</para>
|
||||
<section id="thread.rationale.Boost.Thread">
|
||||
<title>Rationale for the Creation of &Boost.Thread;</title>
|
||||
<para>Processes often have a degree of "potential parallelism" and it can
|
||||
often be more intuitive to design systems with this in mind. Further, these
|
||||
parallel processes can result in more responsive programs. The benefits for
|
||||
multithreaded programming are quite well known to most modern programmers,
|
||||
yet the C++ language doesn't directly support this concept.</para>
|
||||
<para>Many platforms support multithreaded programming despite the fact that
|
||||
the language doesn't support it. They do this through external libraries,
|
||||
which are, unfortunately, platform specific. POSIX has tried to address this
|
||||
problem through the standardization of a "pthread" library. However, this is
|
||||
a standard only on POSIX platforms, so its portability is limited.</para>
|
||||
<para>Another problem with POSIX and other platform specific thread
|
||||
libraries is that they are almost universally C based libraries. This leaves
|
||||
several C++ specific issues unresolved, such as what happens when an
|
||||
exception is thrown in a thread. Further, there are some C++ concepts, such
|
||||
as destructors, that can make usage much easier than what's available in a C
|
||||
library.</para>
|
||||
<para>What's truly needed is C++ language support for threads. However, the
|
||||
C++ standards committee needs existing practice or a good proposal as a
|
||||
starting point for adding this to the standard.</para>
|
||||
<para>The &Boost.Thread; library was developed to provide a C++ developer
|
||||
with a portable interface for writing multithreaded programs on numerous
|
||||
platforms. There's a hope that the library can be the basis for a more
|
||||
detailed proposal for the C++ standards committee to consider for inclusion
|
||||
in the next C++ standard.</para>
|
||||
</section>
|
||||
<section id="thread.rationale.primitives">
|
||||
<title>Rationale for the Low Level Primitives Supported in &Boost.Thread;</title>
|
||||
<para>The &Boost.Thread; library supplies a set of low level primitives for
|
||||
writing multithreaded programs, such as mutexes and condition variables. In
|
||||
fact, the first release of &Boost.Thread; supports only these low level
|
||||
primitives. However, computer science research has shown that use of these
|
||||
primitives is difficult since it's difficult to mathematically prove that a
|
||||
usage pattern is correct, meaning it doesn't result in race conditions or
|
||||
deadlocks. There are several algebras (such as CSP, CCS and Join calculus)
|
||||
that have been developed to help write provably correct parallel
|
||||
processes. In order to prove the correctness these processes must be coded
|
||||
using higher level abstractions. So why does &Boost.Thread; support the
|
||||
lower level concepts?</para>
|
||||
<para>The reason is simple: the higher level concepts need to be implemented
|
||||
using at least some of the lower level concepts. So having portable lower
|
||||
level concepts makes it easier to develop the higher level concepts and will
|
||||
allow researchers to experiment with various techniques.</para>
|
||||
<para>Beyond this theoretical application of higher level concepts, however,
|
||||
the fact remains that many multithreaded programs are written using only the
|
||||
lower level concepts, so they are useful in and of themselves, even if it's
|
||||
hard to prove that their usage is correct. Since many users will be familiar
|
||||
with these lower level concepts but unfamiliar with any of the higher
|
||||
level concepts, supporting the lower level concepts provides
|
||||
greater accessibility.</para>
|
||||
</section>
|
||||
<section id="thread.rationale.locks">
|
||||
<title>Rationale for the Lock Design</title>
|
||||
<para>Programmers who are used to multithreaded programming issues will
|
||||
quickly note that the &Boost.Thread; design for mutex lock concepts is not
|
||||
<link linkend="thread.glossary.thread-safe">thread-safe</link> (this is
|
||||
clearly documented as well). At first this may seem like a serious design
|
||||
flaw. Why have a multithreading primitive that's not thread-safe
|
||||
itself?</para>
|
||||
<para>A lock object is not a synchronization primitive. A lock object's sole
|
||||
responsibility is to ensure that a mutex is both locked and unlocked in a
|
||||
manner that won't result in the common error of locking a mutex and then
|
||||
forgetting to unlock it. This means that instances of a lock object are only
|
||||
going to be created, at least in theory, within block scope and won't be
|
||||
shared between threads. Only the mutex objects will be created outside of
|
||||
block scope and/or shared between threads. Though it's possible to create a
|
||||
lock object outside of block scope and to share it between threads, to do so
|
||||
would not be a typical usage (in fact, to do so would likely be an
|
||||
error). Nor are there any cases when such usage would be required.</para>
|
||||
<para>Lock objects must maintain some state information. In order to allow a
|
||||
program to determine if a try_lock or timed_lock was successful the lock
|
||||
object must retain state indicating the success or failure of the call made
|
||||
in its constructor. If a lock object were to have such state and remain
|
||||
thread-safe it would need to synchronize access to the state information
|
||||
which would result in roughly doubling the time of most operations. Worse,
|
||||
since checking the state can occur only by a call after construction, we'd
|
||||
have a race condition if the lock object were shared between threads.</para>
|
||||
<para>So, to avoid the overhead of synchronizing access to the state
|
||||
information and to avoid the race condition, the &Boost.Thread; library
|
||||
simply does nothing to make lock objects thread-safe. Instead, sharing a
|
||||
lock object between threads results in undefined behavior. Since the only
|
||||
proper usage of lock objects is within block scope this isn't a problem, and
|
||||
so long as the lock object is properly used there's no danger of any
|
||||
multithreading issues.</para>
|
||||
</section>
|
||||
<section id="thread.rationale.non-copyable">
|
||||
<title>Rationale for NonCopyable Thread Type</title>
|
||||
<para>Programmers who are used to C libraries for multithreaded programming
|
||||
are likely to wonder why &Boost.Thread; uses a noncopyable design for
|
||||
<classname>boost::thread</classname>. After all, the C thread types are
|
||||
copyable, and you often have a need for copying them within user
|
||||
code. However, careful comparison of C designs to C++ designs shows a flaw
|
||||
in this logic.</para>
|
||||
<para>All C types are copyable. It is, in fact, not possible to make a
|
||||
noncopyable type in C. For this reason types that represent system resources
|
||||
in C are often designed to behave very similarly to a pointer to dynamic
|
||||
memory. There's an API for acquiring the resource and an API for releasing
|
||||
the resource. For memory we have pointers as the type and alloc/free for
|
||||
the acquisition and release APIs. For files we have FILE* as the type and
|
||||
fopen/fclose for the acquisition and release APIs. You can freely copy
|
||||
instances of the types but must manually manage the lifetime of the actual
|
||||
resource through the acquisition and release APIs.</para>
|
||||
<para>C++ designs recognize that the acquisition and release APIs are error
|
||||
prone and try to eliminate possible errors by acquiring the resource in the
|
||||
constructor and releasing it in the destructor. The best example of such a
|
||||
design is the std::iostream set of classes which can represent the same
|
||||
resource as the FILE* type in C. A file is opened in the std::fstream's
|
||||
constructor and closed in its destructor. However, if an iostream were
|
||||
copyable it could lead to a file being closed twice, an obvious error, so
|
||||
the std::iostream types are noncopyable by design. This is the same design
|
||||
used by boost::thread, which is a simple and easy to understand design
|
||||
that's consistent with other C++ standard types.</para>
|
||||
<para>During the design of boost::thread it was pointed out that it would be
|
||||
possible to allow it to be a copyable type if some form of "reference
|
||||
management" were used, such as ref-counting or ref-lists, and many argued
|
||||
for a boost::thread_ref design instead. The reasoning was that copying
|
||||
"thread" objects was a typical need in the C libraries, and so presumably
|
||||
would be in the C++ libraries as well. It was also thought that
|
||||
implementations could provide more efficient reference management than
|
||||
wrappers (such as boost::shared_ptr) around a noncopyable thread
|
||||
concept. Analysis of whether or not these arguments would hold true doesn't
|
||||
appear to bear them out. To illustrate the analysis we'll first provide
|
||||
pseudo-code illustrating the six typical usage patterns of a thread
|
||||
object.</para>
|
||||
<section id="thread.rationale.non-copyable.simple">
|
||||
<title>1. Use case: Simple creation of a thread.</title>
|
||||
<programlisting>
|
||||
void foo()
|
||||
{
|
||||
create_thread(&bar);
|
||||
}
|
||||
</programlisting>
|
||||
</section>
|
||||
<section id="thread.rationale.non-copyable.joined">
|
||||
<title>2. Use case: Creation of a thread that's later joined.</title>
|
||||
<programlisting>
|
||||
void foo()
|
||||
{
|
||||
thread = create_thread(&bar);
|
||||
join(thread);
|
||||
}
|
||||
</programlisting>
|
||||
</section>
|
||||
<section id="thread.rationale.non-copyable.loop">
|
||||
<title>3. Use case: Simple creation of several threads in a loop.</title>
|
||||
<programlisting>
|
||||
void foo()
|
||||
{
|
||||
for (int i=0; i<NUM_THREADS; ++i)
|
||||
create_thread(&bar);
|
||||
}
|
||||
</programlisting>
|
||||
</section>
|
||||
<section id="thread.rationale.non-copyable.loop-join">
|
||||
<title>4. Use case: Creation of several threads in a loop which are later joined.</title>
|
||||
<programlisting>
|
||||
void foo()
|
||||
{
|
||||
for (int i=0; i<NUM_THREADS; ++i)
|
||||
threads[i] = create_thread(&bar);
|
||||
for (int i=0; i<NUM_THREADS; ++i)
|
||||
threads[i].join();
|
||||
}
|
||||
</programlisting>
|
||||
</section>
|
||||
<section id="thread.rationale.non-copyable.pass">
|
||||
<title>5. Use case: Creation of a thread whose ownership is passed to another object/method.</title>
|
||||
<programlisting>
|
||||
void foo()
|
||||
{
|
||||
thread = create_thread(&bar);
|
||||
manager.owns(thread);
|
||||
}
|
||||
</programlisting>
|
||||
</section>
|
||||
<section id="thread.rationale.non-copyable.shared">
|
||||
<title>6. Use case: Creation of a thread whose ownership is shared between multiple
|
||||
objects.</title>
|
||||
<programlisting>
|
||||
void foo()
|
||||
{
|
||||
thread = create_thread(&bar);
|
||||
manager1.add(thread);
|
||||
manager2.add(thread);
|
||||
}
|
||||
</programlisting>
|
||||
</section>
|
||||
<para>Of these usage patterns there's only one that requires reference
|
||||
management (number 6). Hopefully it's fairly obvious that this usage pattern
|
||||
simply won't occur as often as the other usage patterns. So there really
|
||||
isn't a "typical need" for a thread concept, though there is some
|
||||
need.</para>
|
||||
<para>Since the need isn't typical we must use different criteria for
|
||||
deciding on either a thread_ref or thread design. Possible criteria include
|
||||
ease of use and performance. So let's analyze both of these
|
||||
carefully.</para>
|
||||
<para>With ease of use we can look at existing experience. The standard C++
|
||||
objects that represent a system resource, such as std::iostream, are
|
||||
noncopyable, so we know that C++ programmers must at least be experienced
|
||||
with this design. Most C++ developers are also used to smart pointers such
|
||||
as boost::shared_ptr, so we know they can at least adapt to a thread_ref
|
||||
concept with little effort. So existing experience isn't going to lead us to
|
||||
a choice.</para>
|
||||
<para>The other thing we can look at is how difficult it is to use both
|
||||
types for the six usage patterns above. If we find it overly difficult to
|
||||
use a concept for any of the usage patterns there would be a good argument
|
||||
for choosing the other design. So we'll code all six usage patterns using
|
||||
both designs.</para>
|
||||
<section id="thread.rationale_comparison.non-copyable.simple">
|
||||
<title>1. Comparison: simple creation of a thread.</title>
|
||||
<programlisting>
|
||||
void foo()
|
||||
{
|
||||
thread thrd(&bar);
|
||||
}
|
||||
void foo()
|
||||
{
|
||||
thread_ref thrd = create_thread(&bar);
|
||||
}
|
||||
</programlisting>
|
||||
</section>
|
||||
<section id="thread.rationale_comparison.non-copyable.joined">
|
||||
<title>2. Comparison: creation of a thread that's later joined.</title>
|
||||
<programlisting>
|
||||
void foo()
|
||||
{
|
||||
thread thrd(&bar);
|
||||
thrd.join();
|
||||
}
|
||||
void foo()
|
||||
{
|
||||
thread_ref thrd =
|
||||
create_thread(&bar);thrd->join();
|
||||
}
|
||||
</programlisting>
|
||||
</section>
|
||||
<section id="thread.rationale_comparison.non-copyable.loop">
|
||||
<title>3. Comparison: simple creation of several threads in a loop.</title>
|
||||
<programlisting>
|
||||
void foo()
|
||||
{
|
||||
for (int i=0; i<NUM_THREADS; ++i)
|
||||
thread thrd(&bar);
|
||||
}
|
||||
void foo()
|
||||
{
|
||||
for (int i=0; i<NUM_THREADS; ++i)
|
||||
thread_ref thrd = create_thread(&bar);
|
||||
}
|
||||
</programlisting>
|
||||
</section>
|
||||
<section id="thread.rationale_comparison.non-copyable.loop-join">
|
||||
<title>4. Comparison: creation of several threads in a loop which are later joined.</title>
|
||||
<programlisting>
|
||||
void foo()
|
||||
{
|
||||
std::auto_ptr<thread> threads[NUM_THREADS];
|
||||
for (int i=0; i<NUM_THREADS; ++i)
|
||||
threads[i] = std::auto_ptr<thread>(new thread(&bar));
|
||||
for (int i= 0; i<NUM_THREADS;
|
||||
++i)threads[i]->join();
|
||||
}
|
||||
void foo()
|
||||
{
|
||||
thread_ref threads[NUM_THREADS];
|
||||
for (int i=0; i<NUM_THREADS; ++i)
|
||||
threads[i] = create_thread(&bar);
|
||||
for (int i= 0; i<NUM_THREADS;
|
||||
++i)threads[i]->join();
|
||||
}
|
||||
</programlisting>
|
||||
</section>
|
||||
<section id="thread.rationale_comparison.non-copyable.pass">
|
||||
<title>5. Comparison: creation of a thread whose ownership is passed to another object/method.</title>
|
||||
<programlisting>
|
||||
void foo()
|
||||
{
|
||||
thread thrd* = new thread(&bar);
|
||||
manager.owns(thread);
|
||||
}
|
||||
void foo()
|
||||
{
|
||||
thread_ref thrd = create_thread(&bar);
|
||||
manager.owns(thrd);
|
||||
}
|
||||
</programlisting>
|
||||
</section>
|
||||
<section id="thread.rationale_comparison.non-copyable.shared">
|
||||
<title>6. Comparison: creation of a thread whose ownership is shared
|
||||
between multiple objects.</title>
|
||||
<programlisting>
|
||||
void foo()
|
||||
{
|
||||
boost::shared_ptr<thread> thrd(new thread(&bar));
|
||||
manager1.add(thrd);
|
||||
manager2.add(thrd);
|
||||
}
|
||||
void foo()
|
||||
{
|
||||
thread_ref thrd = create_thread(&bar);
|
||||
manager1.add(thrd);
|
||||
manager2.add(thrd);
|
||||
}
|
||||
</programlisting>
|
||||
</section>
|
||||
<para>This shows the usage patterns being nearly identical in complexity for
|
||||
both designs. The only actual added complexity occurs because of the use of
|
||||
operator new in
|
||||
<link linkend="thread.rationale_comparison.non-copyable.loop-join">(4)</link>,
|
||||
<link linkend="thread.rationale_comparison.non-copyable.pass">(5)</link>, and
|
||||
<link linkend="thread.rationale_comparison.non-copyable.shared">(6)</link>;
|
||||
and the use of std::auto_ptr and boost::shared_ptr in
|
||||
<link linkend="thread.rationale_comparison.non-copyable.loop-join">(4)</link> and
|
||||
<link linkend="thread.rationale_comparison.non-copyable.shared">(6)</link>
|
||||
respectively. However, that's not really
|
||||
much added complexity, and C++ programmers are used to using these idioms
|
||||
anyway. Some may dislike the presence of operator new in user code, but
|
||||
this can be eliminated by proper design of higher level concepts, such as
|
||||
the boost::thread_group class that simplifies example
|
||||
<link linkend="thread.rationale_comparison.non-copyable.loop-join">(4)</link>
|
||||
down to:</para>
|
||||
<programlisting>
|
||||
void foo()
|
||||
{
|
||||
thread_group threads;
|
||||
for (int i=0; i<NUM_THREADS; ++i)
|
||||
threads.create_thread(&bar);
|
||||
threads.join_all();
|
||||
}
|
||||
</programlisting>
|
||||
<para>So ease of use is really a wash and not much help in picking a
|
||||
design.</para>
|
||||
<para>So what about performance? Looking at the above code examples,
|
||||
we can analyze the theoretical impact to performance that both designs
|
||||
have. For <link linkend="thread.rationale_comparison.non-copyable.simple">(1)</link>
|
||||
we can see that platforms that don't have a ref-counted native
|
||||
thread type (POSIX, for instance) will be impacted by a thread_ref
|
||||
design. Even if the native thread type is ref-counted there may be an impact
|
||||
if more state information has to be maintained for concepts foreign to the
|
||||
native API, such as clean up stacks for Win32 implementations.
|
||||
For <link linkend="thread.rationale_comparison.non-copyable.joined">(2)</link>
|
||||
and <link linkend="thread.rationale_comparison.non-copyable.loop">(3)</link>
|
||||
the performance impact will be identical to
|
||||
<link linkend="thread.rationale_comparison.non-copyable.simple">(1)</link>.
|
||||
For <link linkend="thread.rationale_comparison.non-copyable.loop-join">(4)</link>
|
||||
things get a little more interesting and we find that theoretically at least
|
||||
the thread_ref may perform faster since the thread design requires dynamic
|
||||
memory allocation/deallocation. However, in practice there may be dynamic
|
||||
allocation for the thread_ref design as well, it will just be hidden from
|
||||
the user. As long as the implementation has to do dynamic allocations the
|
||||
thread_ref loses again because of the reference management. For
|
||||
<link linkend="thread.rationale_comparison.non-copyable.pass">(5)</link> we see
|
||||
the same impact as we do for
|
||||
<link linkend="thread.rationale_comparison.non-copyable.loop-join">(4)</link>.
|
||||
For <link linkend="thread.rationale_comparison.non-copyable.shared">(6)</link>
|
||||
we still have a possible impact to
|
||||
the thread design because of dynamic allocation but thread_ref no longer
|
||||
suffers because of its reference management, and in fact, theoretically at
|
||||
least, the thread_ref may do a better job of managing the references. All of
|
||||
this indicates that thread wins for
|
||||
<link linkend="thread.rationale_comparison.non-copyable.simple">(1)</link>,
|
||||
<link linkend="thread.rationale_comparison.non-copyable.joined">(2)</link> and
|
||||
<link linkend="thread.rationale_comparison.non-copyable.loop">(3)</link>; with
|
||||
<link linkend="thread.rationale_comparison.non-copyable.loop-join">(4)</link>
|
||||
and <link linkend="thread.rationale_comparison.non-copyable.pass">(5)</link> the
|
||||
winner depending on the implementation and the platform but with the thread design
|
||||
probably having a better chance; and with
|
||||
<link linkend="thread.rationale_comparison.non-copyable.shared">(6)</link>
|
||||
it will again depend on the
|
||||
implementation and platform but this time we favor thread_ref
|
||||
slightly. Given all of this it's a narrow margin, but the thread design
|
||||
prevails.</para>
|
||||
<para>Given this analysis, and the fact that noncopyable objects for system
|
||||
resources are the normal designs that C++ programmers are used to dealing
|
||||
with, the &Boost.Thread; library has gone with a noncopyable design.</para>
|
||||
</section>
|
||||
<section id="thread.rationale.events">
|
||||
<title>Rationale for not providing <emphasis>Event Variables</emphasis></title>
|
||||
<para><emphasis>Event variables</emphasis> are simply far too
|
||||
error-prone. <classname>boost::condition</classname> variables are a much safer
|
||||
alternative. [Note that Graphical User Interface <emphasis>events</emphasis> are
|
||||
a different concept, and are not what is being discussed here.]</para>
|
||||
<para>Event variables were one of the first synchronization primitives. They
|
||||
are still used today, for example, in the native Windows multithreading
|
||||
API. Yet both respected computer science researchers and experienced
|
||||
multithreading practitioners believe event variables are so inherently
|
||||
error-prone that they should never be used, and thus should not be part of a
|
||||
multithreading library.</para>
|
||||
<para>Per Brinch Hansen &cite.Hansen73; analyzed event variables in some
|
||||
detail, pointing out [emphasis his] that "<emphasis>event operations force
|
||||
the programmer to be aware of the relative speeds of the sending and
|
||||
receiving processes</emphasis>". His summary:</para>
|
||||
<blockquote>
|
||||
<para>We must therefore conclude that event variables of the previous type
|
||||
are impractical for system design. <emphasis>The effect of an interaction
|
||||
between two processes must be independent of the speed at which it is
|
||||
carried out.</emphasis></para>
|
||||
</blockquote>
|
||||
<para>Experienced programmers using the Windows platform today report that
|
||||
event variables are a continuing source of errors, even after previous bad
|
||||
experiences caused them to be very careful in their use of event
|
||||
variables. Overt problems can be avoided, for example, by teaming the event
|
||||
variable with a mutex, but that may just convert a <link
|
||||
linkend="thread.glossary.race-condition">race condition</link> into another
|
||||
problem, such as excessive resource use. One of the most distressing aspects
|
||||
of the experience reports is the claim that many defects are latent. That
|
||||
is, the programs appear to work correctly, but contain hidden timing
|
||||
dependencies which will cause them to fail when environmental factors or
|
||||
usage patterns change, altering relative thread timings.</para>
|
||||
<para>The decision to exclude event variables from &Boost.Thread; has been
|
||||
surprising to some Windows programmers. They have written programs which
|
||||
work using event variables, and wonder what the problem is. It seems similar
|
||||
to the "goto considered harmful" controversy of 30 years ago. It isn't that
|
||||
events, like gotos, can't be made to work, but rather that virtually all
|
||||
programs using alternatives will be easier to write, debug, read, maintain,
|
||||
and will be less likely to contain latent defects.</para>
|
||||
<para>[Rationale provided by Beman Dawes]</para>
|
||||
</section>
|
||||
</section>
|
||||
@@ -1,492 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/read_write_mutex.hpp"
|
||||
last-revision="$Date$">
|
||||
<namespace name="boost">
|
||||
<namespace name="read_write_scheduling_policy">
|
||||
<enum name="read_write_scheduling_policy">
|
||||
<enumvalue name="writer_priority" />
|
||||
<enumvalue name="reader_priority" />
|
||||
<enumvalue name="alternating_many_reads" />
|
||||
<enumvalue name="alternating_single_read" />
|
||||
|
||||
<purpose>
|
||||
<para>Specifies the
|
||||
<link linkend="thread.concepts.read-write-scheduling-policies.inter-class">inter-class sheduling policy</link>
|
||||
to use when a set of threads try to obtain different types of
|
||||
locks simultaneously.</para>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<para>The only clock type supported by &Boost.Thread; is
|
||||
<code>TIME_UTC</code>. The epoch for <code>TIME_UTC</code>
|
||||
is 1970-01-01 00:00:00.</para>
|
||||
</description>
|
||||
</enum>
|
||||
</namespace>
|
||||
|
||||
<class name="read_write_mutex">
|
||||
<purpose>
|
||||
<para>The <classname>read_write_mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.ReadWriteMutex">ReadWriteMutex</link> concept.</para>
|
||||
<note> Unfortunately it turned out that the current implementation of Read/Write Mutex has
|
||||
some serious problems. So it was decided not to put this implementation into
|
||||
release grade code. Also discussions on the mailing list led to the
|
||||
conclusion that the current concepts need to be rethought. In particular
|
||||
the schedulings <link linkend="thread.concepts.read-write-scheduling-policies.inter-class">
|
||||
Inter-Class Scheduling Policies</link> are deemed unnecessary.
|
||||
There seems to be common belief that a fair scheme suffices.
|
||||
The following documentation has been retained however, to give
|
||||
readers of this document the opportunity to study the original design.
|
||||
</note>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<para>The <classname>read_write_mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.ReadWriteMutex">ReadWriteMutex</link> concept.
|
||||
It should be used to synchronize access to shared resources using
|
||||
<link linkend="thread.concepts.read-write-locking-strategies.unspecified">Unspecified</link>
|
||||
locking mechanics.</para>
|
||||
|
||||
<para>For classes that model related mutex concepts, see
|
||||
<classname>try_read_write_mutex</classname> and <classname>timed_read_write_mutex</classname>.</para>
|
||||
|
||||
<para>The <classname>read_write_mutex</classname> class supplies the following typedefs,
|
||||
which <link linkend="thread.concepts.read-write-lock-models">model</link>
|
||||
the specified locking strategies:
|
||||
|
||||
<informaltable>
|
||||
<tgroup cols="2" align="left">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Lock Name</entry>
|
||||
<entry>Lock Concept</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>scoped_read_write_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedReadWriteLock">ScopedReadWriteLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_read_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedLock">ScopedLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_write_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedLock">ScopedLock</link></entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
</para>
|
||||
|
||||
<para>The <classname>read_write_mutex</classname> class uses an
|
||||
<link linkend="thread.concepts.read-write-locking-strategies.unspecified">Unspecified</link>
|
||||
locking strategy, so attempts to recursively lock a <classname>read_write_mutex</classname>
|
||||
object or attempts to unlock one by threads that don't own a lock on it result in
|
||||
<emphasis role="bold">undefined behavior</emphasis>.
|
||||
This strategy allows implementations to be as efficient as possible
|
||||
on any given platform. It is, however, recommended that
|
||||
implementations include debugging support to detect misuse when
|
||||
<code>NDEBUG</code> is not defined.</para>
|
||||
|
||||
<para>Like all
|
||||
<link linkend="thread.concepts.read-write-mutex-models">read/write mutex models</link>
|
||||
in &Boost.Thread;, <classname>read_write_mutex</classname> has two types of
|
||||
<link linkend="thread.concepts.read-write-scheduling-policies">scheduling policies</link>, an
|
||||
<link linkend="thread.concepts.read-write-scheduling-policies.inter-class">inter-class sheduling policy</link>
|
||||
between threads trying to obtain different types of locks and an
|
||||
<link linkend="thread.concepts.read-write-scheduling-policies.intra-class">intra-class sheduling policy</link>
|
||||
between threads trying to obtain the same type of lock.
|
||||
The <classname>read_write_mutex</classname> class allows the
|
||||
programmer to choose what
|
||||
<link linkend="thread.concepts.read-write-scheduling-policies.inter-class">inter-class sheduling policy</link>
|
||||
will be used; however, like all read/write mutex models,
|
||||
<classname>read_write_mutex</classname> leaves the
|
||||
<link linkend="thread.concepts.read-write-scheduling-policies.intra-class">intra-class sheduling policy</link> as
|
||||
<link linkend="thread.concepts.read-write-locking-strategies.unspecified">Unspecified</link>.
|
||||
</para>
|
||||
|
||||
<note>Self-deadlock is virtually guaranteed if a thread tries to
|
||||
lock the same <classname>read_write_mutex</classname> multiple times
|
||||
unless all locks are read-locks (but see below)</note>
|
||||
</description>
|
||||
|
||||
<inherit access="private">
|
||||
<type><classname>boost::noncopyable</classname></type>
|
||||
<purpose>Exposition only</purpose>
|
||||
</inherit>
|
||||
|
||||
<inherit access="private">
|
||||
<type><classname>boost::noncopyable</classname></type>
|
||||
<purpose>Exposition only</purpose>
|
||||
</inherit>
|
||||
|
||||
<typedef name="scoped_read_write_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_read_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_write_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<constructor>
|
||||
<parameter name="count">
|
||||
<paramtype>boost::read_write_scheduling_policy</paramtype>
|
||||
</parameter>
|
||||
|
||||
<effects>Constructs a <classname>read_write_mutex</classname> object.
|
||||
</effects>
|
||||
|
||||
<postconditions><code>*this</code> is in an unlocked state.
|
||||
</postconditions>
|
||||
</constructor>
|
||||
|
||||
<destructor>
|
||||
<effects>Destroys a <classname>read_write_mutex</classname> object.</effects>
|
||||
|
||||
<requires><code>*this</code> is in an unlocked state.</requires>
|
||||
|
||||
<notes><emphasis role="bold">Danger:</emphasis> Destruction of a
|
||||
locked mutex is a serious programming error resulting in undefined
|
||||
behavior such as a program crash.</notes>
|
||||
</destructor>
|
||||
</class>
|
||||
|
||||
<class name="try_read_write_mutex">
|
||||
<purpose>
|
||||
<para>The <classname>try_read_write_mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.TryReadWriteMutex">TryReadWriteMutex</link> concept.</para>
|
||||
<note> Unfortunately it turned out that the current implementation of Read/Write Mutex has
|
||||
some serious problems. So it was decided not to put this implementation into
|
||||
release grade code. Also discussions on the mailing list led to the
|
||||
conclusion that the current concepts need to be rethought. In particular
|
||||
the schedulings <link linkend="thread.concepts.read-write-scheduling-policies.inter-class">
|
||||
Inter-Class Scheduling Policies</link> are deemed unnecessary.
|
||||
There seems to be common belief that a fair scheme suffices.
|
||||
The following documentation has been retained however, to give
|
||||
readers of this document the opportunity to study the original design.
|
||||
</note>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<para>The <classname>try_read_write_mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.TryReadWriteMutex">TryReadWriteMutex</link> concept.
|
||||
It should be used to synchronize access to shared resources using
|
||||
<link linkend="thread.concepts.read-write-locking-strategies.unspecified">Unspecified</link>
|
||||
locking mechanics.</para>
|
||||
|
||||
<para>For classes that model related mutex concepts, see
|
||||
<classname>read_write_mutex</classname> and <classname>timed_read_write_mutex</classname>.</para>
|
||||
|
||||
<para>The <classname>try_read_write_mutex</classname> class supplies the following typedefs,
|
||||
which <link linkend="thread.concepts.read-write-lock-models">model</link>
|
||||
the specified locking strategies:
|
||||
|
||||
<informaltable>
|
||||
<tgroup cols="2" align="left">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Lock Name</entry>
|
||||
<entry>Lock Concept</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>scoped_read_write_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedReadWriteLock">ScopedReadWriteLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_try_read_write_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedTryReadWriteLock">ScopedTryReadWriteLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_read_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedLock">ScopedLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_try_read_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedTryLock">ScopedTryLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_write_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedLock">ScopedLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_try_write_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedTryLock">ScopedTryLock</link></entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
</para>
|
||||
|
||||
<para>The <classname>try_read_write_mutex</classname> class uses an
|
||||
<link linkend="thread.concepts.read-write-locking-strategies.unspecified">Unspecified</link>
|
||||
locking strategy, so attempts to recursively lock a <classname>try_read_write_mutex</classname>
|
||||
object or attempts to unlock one by threads that don't own a lock on it result in
|
||||
<emphasis role="bold">undefined behavior</emphasis>.
|
||||
This strategy allows implementations to be as efficient as possible
|
||||
on any given platform. It is, however, recommended that
|
||||
implementations include debugging support to detect misuse when
|
||||
<code>NDEBUG</code> is not defined.</para>
|
||||
|
||||
<para>Like all
|
||||
<link linkend="thread.concepts.read-write-mutex-models">read/write mutex models</link>
|
||||
in &Boost.Thread;, <classname>try_read_write_mutex</classname> has two types of
|
||||
<link linkend="thread.concepts.read-write-scheduling-policies">scheduling policies</link>, an
|
||||
<link linkend="thread.concepts.read-write-scheduling-policies.inter-class">inter-class sheduling policy</link>
|
||||
between threads trying to obtain different types of locks and an
|
||||
<link linkend="thread.concepts.read-write-scheduling-policies.intra-class">intra-class sheduling policy</link>
|
||||
between threads trying to obtain the same type of lock.
|
||||
The <classname>try_read_write_mutex</classname> class allows the
|
||||
programmer to choose what
|
||||
<link linkend="thread.concepts.read-write-scheduling-policies.inter-class">inter-class sheduling policy</link>
|
||||
will be used; however, like all read/write mutex models,
|
||||
<classname>try_read_write_mutex</classname> leaves the
|
||||
<link linkend="thread.concepts.read-write-scheduling-policies.intra-class">intra-class sheduling policy</link> as
|
||||
<link linkend="thread.concepts.unspecified-scheduling-policy">Unspecified</link>.
|
||||
</para>
|
||||
|
||||
<note>Self-deadlock is virtually guaranteed if a thread tries to
|
||||
lock the same <classname>try_read_write_mutex</classname> multiple times
|
||||
unless all locks are read-locks (but see below)</note>
|
||||
</description>
|
||||
|
||||
<inherit access="private">
|
||||
<type><classname>boost::noncopyable</classname></type>
|
||||
<purpose>Exposition only</purpose>
|
||||
</inherit>
|
||||
|
||||
<typedef name="scoped_read_write_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_try_read_write_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_read_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_try_read_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_write_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_try_write_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<constructor>
|
||||
<parameter name="count">
|
||||
<paramtype>boost::read_write_scheduling_policy</paramtype>
|
||||
</parameter>
|
||||
|
||||
<effects>Constructs a <classname>try_read_write_mutex</classname> object.
|
||||
</effects>
|
||||
|
||||
<postconditions><code>*this</code> is in an unlocked state.
|
||||
</postconditions>
|
||||
</constructor>
|
||||
|
||||
<destructor>
|
||||
<effects>Destroys a <classname>try_read_write_mutex</classname> object.</effects>
|
||||
|
||||
<requires><code>*this</code> is in an unlocked state.</requires>
|
||||
|
||||
<notes><emphasis role="bold">Danger:</emphasis> Destruction of a
|
||||
locked mutex is a serious programming error resulting in undefined
|
||||
behavior such as a program crash.</notes>
|
||||
</destructor>
|
||||
</class>
|
||||
|
||||
<class name="timed_read_write_mutex">
|
||||
<purpose>
|
||||
<para>The <classname>timed_read_write_mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.TimedReadWriteMutex">TimedReadWriteMutex</link> concept.</para>
|
||||
<note> Unfortunately it turned out that the current implementation of Read/Write Mutex has
|
||||
some serious problems. So it was decided not to put this implementation into
|
||||
release grade code. Also discussions on the mailing list led to the
|
||||
conclusion that the current concepts need to be rethought. In particular
|
||||
the schedulings <link linkend="thread.concepts.read-write-scheduling-policies.inter-class">
|
||||
Inter-Class Scheduling Policies</link> are deemed unnecessary.
|
||||
There seems to be common belief that a fair scheme suffices.
|
||||
The following documentation has been retained however, to give
|
||||
readers of this document the opportunity to study the original design.
|
||||
</note>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<para>The <classname>timed_read_write_mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.TimedReadWriteMutex">TimedReadWriteMutex</link> concept.
|
||||
It should be used to synchronize access to shared resources using
|
||||
<link linkend="thread.concepts.read-write-locking-strategies.unspecified">Unspecified</link>
|
||||
locking mechanics.</para>
|
||||
|
||||
<para>For classes that model related mutex concepts, see
|
||||
<classname>read_write_mutex</classname> and <classname>try_read_write_mutex</classname>.</para>
|
||||
|
||||
<para>The <classname>timed_read_write_mutex</classname> class supplies the following typedefs,
|
||||
which <link linkend="thread.concepts.read-write-lock-models">model</link>
|
||||
the specified locking strategies:
|
||||
|
||||
<informaltable>
|
||||
<tgroup cols="2" align="left">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Lock Name</entry>
|
||||
<entry>Lock Concept</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>scoped_read_write_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedReadWriteLock">ScopedReadWriteLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_try_read_write_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedTryReadWriteLock">ScopedTryReadWriteLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_timed_read_write_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedTimedReadWriteLock">ScopedTimedReadWriteLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_read_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedLock">ScopedLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_try_read_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedTryLock">ScopedTryLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_timed_read_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedTimedLock">ScopedTimedLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_write_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedLock">ScopedLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_try_write_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedTryLock">ScopedTryLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_timed_write_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedTimedLock">ScopedTimedLock</link></entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
</para>
|
||||
|
||||
<para>The <classname>timed_read_write_mutex</classname> class uses an
|
||||
<link linkend="thread.concepts.read-write-locking-strategies.unspecified">Unspecified</link>
|
||||
locking strategy, so attempts to recursively lock a <classname>timed_read_write_mutex</classname>
|
||||
object or attempts to unlock one by threads that don't own a lock on it result in
|
||||
<emphasis role="bold">undefined behavior</emphasis>.
|
||||
This strategy allows implementations to be as efficient as possible
|
||||
on any given platform. It is, however, recommended that
|
||||
implementations include debugging support to detect misuse when
|
||||
<code>NDEBUG</code> is not defined.</para>
|
||||
|
||||
<para>Like all
|
||||
<link linkend="thread.concepts.read-write-mutex-models">read/write mutex models</link>
|
||||
in &Boost.Thread;, <classname>timed_read_write_mutex</classname> has two types of
|
||||
<link linkend="thread.concepts.read-write-scheduling-policies">scheduling policies</link>, an
|
||||
<link linkend="thread.concepts.read-write-scheduling-policies.inter-class">inter-class sheduling policy</link>
|
||||
between threads trying to obtain different types of locks and an
|
||||
<link linkend="thread.concepts.read-write-scheduling-policies.intra-class">intra-class sheduling policy</link>
|
||||
between threads trying to obtain the same type of lock.
|
||||
The <classname>timed_read_write_mutex</classname> class allows the
|
||||
programmer to choose what
|
||||
<link linkend="thread.concepts.read-write-scheduling-policies.inter-class">inter-class sheduling policy</link>
|
||||
will be used; however, like all read/write mutex models,
|
||||
<classname>timed_read_write_mutex</classname> leaves the
|
||||
<link linkend="thread.concepts.read-write-scheduling-policies.intra-class">intra-class sheduling policy</link> as
|
||||
<link linkend="thread.concepts.unspecified-scheduling-policy">Unspecified</link>.
|
||||
</para>
|
||||
|
||||
<note>Self-deadlock is virtually guaranteed if a thread tries to
|
||||
lock the same <classname>timed_read_write_mutex</classname> multiple times
|
||||
unless all locks are read-locks (but see below)</note>
|
||||
</description>
|
||||
|
||||
<typedef name="scoped_read_write_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_try_read_write_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_timed_read_write_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_read_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_try_read_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_timed_read_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_write_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_try_write_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_timed_write_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<constructor>
|
||||
<parameter name="count">
|
||||
<paramtype>boost::read_write_scheduling_policy</paramtype>
|
||||
</parameter>
|
||||
|
||||
<effects>Constructs a <classname>timed_read_write_mutex</classname> object.
|
||||
</effects>
|
||||
|
||||
<postconditions><code>*this</code> is in an unlocked state.
|
||||
</postconditions>
|
||||
</constructor>
|
||||
|
||||
<destructor>
|
||||
<effects>Destroys a <classname>timed_read_write_mutex</classname> object.</effects>
|
||||
|
||||
<requires><code>*this</code> is in an unlocked state.</requires>
|
||||
|
||||
<notes><emphasis role="bold">Danger:</emphasis> Destruction of a
|
||||
locked mutex is a serious programming error resulting in undefined
|
||||
behavior such as a program crash.</notes>
|
||||
</destructor>
|
||||
</class>
|
||||
</namespace>
|
||||
</header>
|
||||
@@ -1,306 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/recursive_mutex.hpp"
|
||||
last-revision="$Date$">
|
||||
<namespace name="boost">
|
||||
<class name="recursive_mutex">
|
||||
<purpose>
|
||||
<para>The <classname>recursive_mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.Mutex">Mutex</link> concept.</para>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<para>The <classname>recursive_mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.Mutex">Mutex</link> concept.
|
||||
It should be used to synchronize access to shared resources using
|
||||
<link linkend="thread.concepts.recursive-locking-strategy">Recursive</link>
|
||||
locking mechanics.</para>
|
||||
|
||||
<para>For classes that model related mutex concepts, see
|
||||
<classname>recursive_try_mutex</classname> and <classname>recursive_timed_mutex</classname>.</para>
|
||||
|
||||
<para>For <link linkend="thread.concepts.unspecified-locking-strategy">Unspecified</link>
|
||||
locking mechanics, see <classname>mutex</classname>,
|
||||
<classname>try_mutex</classname>, and <classname>timed_mutex</classname>.
|
||||
</para>
|
||||
|
||||
<para>The <classname>recursive_mutex</classname> class supplies the following typedef,
|
||||
which models the specified locking strategy:
|
||||
|
||||
<table>
|
||||
<title>Supported Lock Types</title>
|
||||
<tgroup cols="2" align="left">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Lock Name</entry>
|
||||
<entry>Lock Concept</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>scoped_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedLock">ScopedLock</link></entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
</para>
|
||||
|
||||
<para>The <classname>recursive_mutex</classname> class uses a
|
||||
<link linkend="thread.concepts.recursive-locking-strategy">Recursive</link>
|
||||
locking strategy, so attempts to recursively lock a
|
||||
<classname>recursive_mutex</classname> object
|
||||
succeed and an internal "lock count" is maintained.
|
||||
Attempts to unlock a <classname>recursive_mutex</classname> object
|
||||
by threads that don't own a lock on it result in
|
||||
<emphasis role="bold">undefined behavior</emphasis>.</para>
|
||||
|
||||
<para>Like all
|
||||
<link linkend="thread.concepts.mutex-models">mutex models</link>
|
||||
in &Boost.Thread;, <classname>recursive_mutex</classname> leaves the
|
||||
<link linkend="thread.concepts.sheduling-policies">scheduling policy</link>
|
||||
as <link linkend="thread.concepts.unspecified-scheduling-policy">Unspecified</link>.
|
||||
Programmers should make no assumptions about the order in which
|
||||
waiting threads acquire a lock.</para>
|
||||
</description>
|
||||
|
||||
<inherit access="private">
|
||||
<type><classname>boost::noncopyable</classname></type>
|
||||
<purpose>Exposition only</purpose>
|
||||
</inherit>
|
||||
|
||||
<typedef name="scoped_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<constructor>
|
||||
<effects>Constructs a <classname>recursive_mutex</classname> object.
|
||||
</effects>
|
||||
|
||||
<postconditions><code>*this</code> is in an unlocked state.
|
||||
</postconditions>
|
||||
</constructor>
|
||||
|
||||
<destructor>
|
||||
<effects>Destroys a <classname>recursive_mutex</classname> object.</effects>
|
||||
|
||||
<requires><code>*this</code> is in an unlocked state.</requires>
|
||||
|
||||
<notes><emphasis role="bold">Danger:</emphasis> Destruction of a
|
||||
locked mutex is a serious programming error resulting in undefined
|
||||
behavior such as a program crash.</notes>
|
||||
</destructor>
|
||||
</class>
|
||||
|
||||
<class name="recursive_try_mutex">
|
||||
<purpose>
|
||||
<para>The <classname>recursive_try_mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.TryMutex">TryMutex</link> concept.</para>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<para>The <classname>recursive_try_mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.TryMutex">TryMutex</link> concept.
|
||||
It should be used to synchronize access to shared resources using
|
||||
<link linkend="thread.concepts.recursive-locking-strategy">Recursive</link>
|
||||
locking mechanics.</para>
|
||||
|
||||
<para>For classes that model related mutex concepts, see
|
||||
<classname>recursive_mutex</classname> and <classname>recursive_timed_mutex</classname>.</para>
|
||||
|
||||
<para>For <link linkend="thread.concepts.unspecified-locking-strategy">Unspecified</link>
|
||||
locking mechanics, see <classname>mutex</classname>,
|
||||
<classname>try_mutex</classname>, and <classname>timed_mutex</classname>.
|
||||
</para>
|
||||
|
||||
<para>The <classname>recursive_try_mutex</classname> class supplies the following typedefs,
|
||||
which model the specified locking strategies:
|
||||
|
||||
<table>
|
||||
<title>Supported Lock Types</title>
|
||||
<tgroup cols="2" align="left">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Lock Name</entry>
|
||||
<entry>Lock Concept</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>scoped_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedLock">ScopedLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_try_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedTryLock">ScopedTryLock</link></entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
</para>
|
||||
|
||||
<para>The <classname>recursive_try_mutex</classname> class uses a
|
||||
<link linkend="thread.concepts.recursive-locking-strategy">Recursive</link>
|
||||
locking strategy, so attempts to recursively lock a
|
||||
<classname>recursive_try_mutex</classname> object
|
||||
succeed and an internal "lock count" is maintained.
|
||||
Attempts to unlock a <classname>recursive_mutex</classname> object
|
||||
by threads that don't own a lock on it result in
|
||||
<emphasis role="bold">undefined behavior</emphasis>.</para>
|
||||
|
||||
<para>Like all
|
||||
<link linkend="thread.concepts.mutex-models">mutex models</link>
|
||||
in &Boost.Thread;, <classname>recursive_try_mutex</classname> leaves the
|
||||
<link linkend="thread.concepts.sheduling-policies">scheduling policy</link>
|
||||
as <link linkend="thread.concepts.unspecified-scheduling-policy">Unspecified</link>.
|
||||
Programmers should make no assumptions about the order in which
|
||||
waiting threads acquire a lock.</para>
|
||||
</description>
|
||||
|
||||
<inherit access="private">
|
||||
<type><classname>boost::noncopyable</classname></type>
|
||||
<purpose>Exposition only</purpose>
|
||||
</inherit>
|
||||
|
||||
<typedef name="scoped_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_try_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<constructor>
|
||||
<effects>Constructs a <classname>recursive_try_mutex</classname> object.
|
||||
</effects>
|
||||
|
||||
<postconditions><code>*this</code> is in an unlocked state.
|
||||
</postconditions>
|
||||
</constructor>
|
||||
|
||||
<destructor>
|
||||
<effects>Destroys a <classname>recursive_try_mutex</classname> object.
|
||||
</effects>
|
||||
|
||||
<requires><code>*this</code> is in an unlocked state.</requires>
|
||||
|
||||
<notes><emphasis role="bold">Danger:</emphasis> Destruction of a
|
||||
locked mutex is a serious programming error resulting in undefined
|
||||
behavior such as a program crash.</notes>
|
||||
</destructor>
|
||||
</class>
|
||||
|
||||
<class name="recursive_timed_mutex">
|
||||
<purpose>
|
||||
<para>The <classname>recursive_timed_mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.TimedMutex">TimedMutex</link> concept.</para>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<para>The <classname>recursive_timed_mutex</classname> class is a model of the
|
||||
<link linkend="thread.concepts.TimedMutex">TimedMutex</link> concept.
|
||||
It should be used to synchronize access to shared resources using
|
||||
<link linkend="thread.concepts.recursive-locking-strategy">Recursive</link>
|
||||
locking mechanics.</para>
|
||||
|
||||
<para>For classes that model related mutex concepts, see
|
||||
<classname>recursive_mutex</classname> and <classname>recursive_try_mutex</classname>.</para>
|
||||
|
||||
<para>For <link linkend="thread.concepts.unspecified-locking-strategy">Unspecified</link>
|
||||
locking mechanics, see <classname>mutex</classname>,
|
||||
<classname>try_mutex</classname>, and <classname>timed_mutex</classname>.
|
||||
</para>
|
||||
|
||||
<para>The <classname>recursive_timed_mutex</classname> class supplies the following typedefs,
|
||||
which model the specified locking strategies:
|
||||
|
||||
<table>
|
||||
<title>Supported Lock Types</title>
|
||||
<tgroup cols="2" align="left">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Lock Name</entry>
|
||||
<entry>Lock Concept</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>scoped_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedLock">ScopedLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_try_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedTryLock">ScopedTryLock</link></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>scoped_timed_lock</entry>
|
||||
<entry><link linkend="thread.concepts.ScopedTimedLock">ScopedTimedLock</link></entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
</para>
|
||||
|
||||
<para>The <classname>recursive_timed_mutex</classname> class uses a
|
||||
<link linkend="thread.concepts.recursive-locking-strategy">Recursive</link>
|
||||
locking strategy, so attempts to recursively lock a
|
||||
<classname>recursive_timed_mutex</classname> object
|
||||
succeed and an internal "lock count" is maintained.
|
||||
Attempts to unlock a <classname>recursive_mutex</classname> object
|
||||
by threads that don't own a lock on it result in
|
||||
<emphasis role="bold">undefined behavior</emphasis>.</para>
|
||||
|
||||
<para>Like all
|
||||
<link linkend="thread.concepts.mutex-models">mutex models</link>
|
||||
in &Boost.Thread;, <classname>recursive_timed_mutex</classname> leaves the
|
||||
<link linkend="thread.concepts.sheduling-policies">scheduling policy</link>
|
||||
as <link linkend="thread.concepts.unspecified-scheduling-policy">Unspecified</link>.
|
||||
Programmers should make no assumptions about the order in which
|
||||
waiting threads acquire a lock.</para>
|
||||
</description>
|
||||
|
||||
<inherit access="private">
|
||||
<type><classname>boost::noncopyable</classname></type>
|
||||
<purpose>Exposition only</purpose>
|
||||
</inherit>
|
||||
|
||||
<typedef name="scoped_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_try_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<typedef name="scoped_timed_lock">
|
||||
<type><emphasis>implementation-defined</emphasis></type>
|
||||
</typedef>
|
||||
|
||||
<constructor>
|
||||
<effects>Constructs a <classname>recursive_timed_mutex</classname> object.
|
||||
</effects>
|
||||
|
||||
<postconditions><code>*this</code> is in an unlocked state.
|
||||
</postconditions>
|
||||
</constructor>
|
||||
|
||||
<destructor>
|
||||
<effects>Destroys a <classname>recursive_timed_mutex</classname> object.</effects>
|
||||
|
||||
<requires><code>*this</code> is in an unlocked state.</requires>
|
||||
|
||||
<notes><emphasis role="bold">Danger:</emphasis> Destruction of a
|
||||
locked mutex is a serious programming error resulting in undefined
|
||||
behavior such as a program crash.</notes>
|
||||
</destructor>
|
||||
</class>
|
||||
</namespace>
|
||||
</header>
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<library-reference id="thread.reference"
|
||||
last-revision="$Date$"
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<xi:include href="barrier-ref.xml"/>
|
||||
<xi:include href="condition-ref.xml"/>
|
||||
<xi:include href="exceptions-ref.xml"/>
|
||||
<xi:include href="mutex-ref.xml"/>
|
||||
<xi:include href="once-ref.xml"/>
|
||||
<xi:include href="recursive_mutex-ref.xml"/>
|
||||
<!--
|
||||
The read_write_mutex is held back from release, since the
|
||||
implementation suffers from a serious, yet unresolved bug.
|
||||
The implementation is likely to appear in a reworked
|
||||
form in the next release.
|
||||
-->
|
||||
<xi:include href="read_write_mutex-ref.xml"/>
|
||||
<xi:include href="thread-ref.xml"/>
|
||||
<xi:include href="tss-ref.xml"/>
|
||||
<xi:include href="xtime-ref.xml"/>
|
||||
</library-reference>
|
||||
@@ -1,204 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.release_notes" last-revision="$Date$">
|
||||
<title>Release Notes</title>
|
||||
<section id="thread.release_notes.boost_1_34_0">
|
||||
<title>Boost 1.34.0</title>
|
||||
|
||||
<section id="thread.release_notes.boost_1_34_0.change_log.maintainance">
|
||||
<title>New team of maintainers</title>
|
||||
|
||||
<para>
|
||||
Since the original author William E. Kempf no longer is available to
|
||||
maintain the &Boost.Thread; library, a new team has been formed
|
||||
in an attempt to continue the work on &Boost.Thread;.
|
||||
Fortunately William E. Kempf has given
|
||||
<ulink url="http://lists.boost.org/Archives/boost/2006/09/110143.php">
|
||||
permission </ulink>
|
||||
to use his work under the boost license.
|
||||
</para>
|
||||
<para>
|
||||
The team currently consists of
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
Anthony Williams, for the Win32 platform,
|
||||
</listitem>
|
||||
<listitem>
|
||||
Roland Schwarz, for the linux platform, and various "housekeeping" tasks.
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
Volunteers for other platforms are welcome!
|
||||
</para>
|
||||
<para>
|
||||
As the &Boost.Thread; was kind of orphaned over the last release, this release
|
||||
attempts to fix the known bugs. Upcoming releases will bring in new things.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="thread.release_notes.boost_1_34_0.change_log.read_write_mutex">
|
||||
<title>read_write_mutex still broken</title>
|
||||
|
||||
<para>
|
||||
<note>
|
||||
It has been decided not to release the Read/Write Mutex, since the current
|
||||
implementation suffers from a serious bug. The documentation of the concepts
|
||||
has been included though, giving the interested reader an opportunity to study the
|
||||
original concepts. Please refer to the following links if you are interested
|
||||
which problems led to the decision to held back this mutex type.The issue
|
||||
has been discovered before 1.33 was released and the code has
|
||||
been omitted from that release. A reworked mutex is expected to appear in 1.35.
|
||||
Also see:
|
||||
<ulink url="http://lists.boost.org/Archives/boost/2005/08/92307.php">
|
||||
read_write_mutex bug</ulink>
|
||||
and
|
||||
<ulink url="http://lists.boost.org/Archives/boost/2005/09/93180.php">
|
||||
read_write_mutex fundamentally broken in 1.33</ulink>
|
||||
</note>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</section>
|
||||
<section id="thread.release_notes.boost_1_32_0">
|
||||
<title>Boost 1.32.0</title>
|
||||
|
||||
<section id="thread.release_notes.boost_1_32_0.change_log.documentation">
|
||||
<title>Documentation converted to BoostBook</title>
|
||||
|
||||
<para>The documentation was converted to BoostBook format,
|
||||
and a number of errors and inconsistencies were
|
||||
fixed in the process.
|
||||
Since this was a fairly large task, there are likely to be
|
||||
more errors and inconsistencies remaining. If you find any,
|
||||
please report them!</para>
|
||||
</section>
|
||||
|
||||
<section id="thread.release_notes.boost_1_32_0.change_log.static_link">
|
||||
<title>Statically-link build option added</title>
|
||||
|
||||
<para>The option to link &Boost.Thread; as a static
|
||||
library has been added (with some limitations on Win32 platforms).
|
||||
This feature was originally removed from an earlier version
|
||||
of Boost because <classname>boost::thread_specific_ptr</classname>
|
||||
required that &Boost.Thread; be dynamically linked in order
|
||||
for its cleanup functionality to work on Win32 platforms.
|
||||
Because this limitation never applied to non-Win32 platforms,
|
||||
because significant progress has been made in removing
|
||||
the limitation on Win32 platforms (many thanks to
|
||||
Aaron LaFramboise and Roland Scwarz!), and because the lack
|
||||
of static linking is one of the most common complaints of
|
||||
&Boost.Thread; users, this decision was reversed.</para>
|
||||
|
||||
<para>On non-Win32 platforms:
|
||||
To choose the dynamically linked version of &Boost.Thread;
|
||||
using Boost's auto-linking feature, #define BOOST_THREAD_USE_DLL;
|
||||
to choose the statically linked version,
|
||||
#define BOOST_THREAD_USE_LIB.
|
||||
If neither symbols is #defined, the default will be chosen.
|
||||
Currently the default is the statically linked version.</para>
|
||||
|
||||
<para>On Win32 platforms using VC++:
|
||||
Use the same #defines as for non-Win32 platforms
|
||||
(BOOST_THREAD_USE_DLL and BOOST_THREAD_USE_LIB).
|
||||
If neither is #defined, the default will be chosen.
|
||||
Currently the default is the statically linked version
|
||||
if the VC++ run-time library is set to
|
||||
"Multi-threaded" or "Multi-threaded Debug", and
|
||||
the dynamically linked version
|
||||
if the VC++ run-time library is set to
|
||||
"Multi-threaded DLL" or "Multi-threaded Debug DLL".</para>
|
||||
|
||||
<para>On Win32 platforms using compilers other than VC++:
|
||||
Use the same #defines as for non-Win32 platforms
|
||||
(BOOST_THREAD_USE_DLL and BOOST_THREAD_USE_LIB).
|
||||
If neither is #defined, the default will be chosen.
|
||||
Currently the default is the dynamically linked version
|
||||
because it has not yet been possible to implement automatic
|
||||
tss cleanup in the statically linked version for compilers
|
||||
other than VC++, although it is hoped that this will be
|
||||
possible in a future version of &Boost.Thread;.
|
||||
|
||||
Note for advanced users: &Boost.Thread; provides several "hook"
|
||||
functions to allow users to experiment with the statically
|
||||
linked version on Win32 with compilers other than VC++.
|
||||
These functions are on_process_enter(), on_process_exit(),
|
||||
on_thread_enter(), and on_thread_exit(), and are defined
|
||||
in tls_hooks.cpp. See the comments in that file for more
|
||||
information.</para>
|
||||
</section>
|
||||
|
||||
<section id="thread.release_notes.boost_1_32_0.change_log.barrier">
|
||||
<title>Barrier functionality added</title>
|
||||
|
||||
<para>A new class, <classname>boost::barrier</classname>, was added.</para>
|
||||
</section>
|
||||
|
||||
<section id="thread.release_notes.boost_1_32_0.change_log.read_write_mutex">
|
||||
<title>Read/write mutex functionality added</title>
|
||||
|
||||
<para>New classes,
|
||||
<classname>boost::read_write_mutex</classname>,
|
||||
<classname>boost::try_read_write_mutex</classname>, and
|
||||
<classname>boost::timed_read_write_mutex</classname>
|
||||
were added.
|
||||
|
||||
<note>Since the read/write mutex and related classes are new,
|
||||
both interface and implementation are liable to change
|
||||
in future releases of &Boost.Thread;.
|
||||
The lock concepts and lock promotion in particular are
|
||||
still under discussion and very likely to change.</note>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="thread.release_notes.boost_1_32_0.change_log.thread_specific_ptr">
|
||||
<title>Thread-specific pointer functionality changed</title>
|
||||
|
||||
<para>The <classname>boost::thread_specific_ptr</classname>
|
||||
constructor now takes an optional pointer to a cleanup function that
|
||||
is called to release the thread-specific data that is being pointed
|
||||
to by <classname>boost::thread_specific_ptr</classname> objects.</para>
|
||||
|
||||
<para>Fixed: the number of available thread-specific storage "slots"
|
||||
is too small on some platforms.</para>
|
||||
|
||||
<para>Fixed: <functionname>thread_specific_ptr::reset()</functionname>
|
||||
doesn't check error returned by <functionname>tss::set()</functionname>
|
||||
(the <functionname>tss::set()</functionname> function now throws
|
||||
if it fails instead of returning an error code).</para>
|
||||
|
||||
<para>Fixed: calling
|
||||
<functionname>boost::thread_specific_ptr::reset()</functionname> or
|
||||
<functionname>boost::thread_specific_ptr::release()</functionname>
|
||||
causes double-delete: once when
|
||||
<functionname>boost::thread_specific_ptr::reset()</functionname> or
|
||||
<functionname>boost::thread_specific_ptr::release()</functionname>
|
||||
is called and once when
|
||||
<functionname>boost::thread_specific_ptr::~thread_specific_ptr()</functionname>
|
||||
is called.</para>
|
||||
</section>
|
||||
|
||||
<section id="thread.release_notes.boost_1_32_0.change_log.mutex">
|
||||
<title>Mutex implementation changed for Win32</title>
|
||||
|
||||
<para>On Win32, <classname>boost::mutex</classname>,
|
||||
<classname>boost::try_mutex</classname>, <classname>boost::recursive_mutex</classname>,
|
||||
and <classname>boost::recursive_try_mutex</classname> now use a Win32 critical section
|
||||
whenever possible; otherwise they use a Win32 mutex. As before,
|
||||
<classname>boost::timed_mutex</classname> and
|
||||
<classname>boost::recursive_timed_mutex</classname> use a Win32 mutex.</para>
|
||||
</section>
|
||||
|
||||
<section id="thread.release_notes.boost_1_32_0.change_log.wince">
|
||||
<title>Windows CE support improved</title>
|
||||
|
||||
<para>Minor changes were made to make Boost.Thread work on Windows CE.</para>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
518
doc/scoped_thread.qbk
Normal file
518
doc/scoped_thread.qbk
Normal file
@@ -0,0 +1,518 @@
|
||||
[/
|
||||
(C) Copyright 2008-9 Anthony Williams.
|
||||
(C) Copyright 12 Vicente J. Botet Escriba.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:ScopedThreads Scoped Threads]
|
||||
|
||||
[heading Synopsis]
|
||||
|
||||
//#include <boost/thread/scoped_thread.hpp>
|
||||
|
||||
struct detach;
|
||||
struct join_if_joinable;
|
||||
struct interrupt_and_join_if_joinable;
|
||||
template <class CallableThread = join_if_joinable>
|
||||
class strict_scoped_thread;
|
||||
template <class CallableThread = join_if_joinable>
|
||||
class scoped_thread;
|
||||
void swap(scoped_thread& lhs,scoped_thread& rhs) noexcept;
|
||||
|
||||
[section:motovation Motivation]
|
||||
Based on the scoped_thread class defined in C++ Concurrency in Action Boost.Thread defines a thread wrapper class that instead of calling terminate if the thread is joinable on destruction, call a specific action given as template parameter.
|
||||
|
||||
While the scoped_thread class defined in C++ Concurrency in Action is closer to strict_scoped_thread class that doesn't allows any change in the wrapped thread, Boost.Thread provides a class scoped_thread that provides the same non-deprecated interface than __thread.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:tutorial Tutorial]
|
||||
|
||||
Scoped Threads are wrappers around a thread that allows the user to state what to do at destruction time. One of the common uses is to join the thread at destruction time so this is the default behavior. This is the single difference respect to a thread. While thread call std::terminate() on the destructor is the thread is joinable, strict_scoped_thread<> or scoped_thread<> join the thread if joinable.
|
||||
|
||||
The difference between strict_scoped_thread and scoped_thread is that the strict_scoped_thread hides completely the owned thread and so the user can do nothing with the owned thread other than the specific action given as parameter, while scoped_thread provide the same interface than __thread and forwards all the operations.
|
||||
|
||||
boost::strict_scoped_thread<> t1((boost::thread(f)));
|
||||
//t1.detach(); // compile fails
|
||||
boost::scoped_thread<> t2((boost::thread(f)));
|
||||
t2.detach();
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:thread_functors Free Thread Functors]
|
||||
|
||||
//#include <boost/thread/scoped_thread.hpp>
|
||||
|
||||
struct detach;
|
||||
struct join_if_joinable;
|
||||
struct interrupt_and_join_if_joinable;
|
||||
|
||||
|
||||
[section:detach Functor `detach`]
|
||||
|
||||
struct detach
|
||||
{
|
||||
void operator()(thread& t)
|
||||
{
|
||||
t.detach();
|
||||
}
|
||||
};
|
||||
[endsect]
|
||||
[section:join_if_joinable Functor `join_if_joinable`]
|
||||
|
||||
struct join_if_joinable
|
||||
{
|
||||
void operator()(thread& t)
|
||||
{
|
||||
if (t.joinable())
|
||||
{
|
||||
t.join();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:interrupt_and_join_if_joinable Functor `interrupt_and_join_if_joinable`]
|
||||
|
||||
struct interrupt_and_join_if_joinable
|
||||
{
|
||||
void operator()(thread& t)
|
||||
{
|
||||
t.interrupt();
|
||||
if (t.joinable())
|
||||
{
|
||||
t.join();
|
||||
}
|
||||
}
|
||||
};
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:strict_scoped_thread Class `strict_scoped_thread`]
|
||||
|
||||
// #include <boost/thread/scoped_thread.hpp>
|
||||
|
||||
template <class CallableThread = join_if_joinable>
|
||||
class strict_scoped_thread
|
||||
{
|
||||
thread t_; // for exposition purposes only
|
||||
public:
|
||||
|
||||
strict_scoped_thread(strict_scoped_thread const&) = delete;
|
||||
strict_scoped_thread& operator=(strict_scoped_thread const&) = delete;
|
||||
|
||||
explicit strict_scoped_thread(thread&& t) noexcept;
|
||||
template <typename F&&, typename ...Args>
|
||||
explicit strict_scoped_thread(F&&, Args&&...);
|
||||
|
||||
~strict_scoped_thread();
|
||||
|
||||
};
|
||||
|
||||
|
||||
RAI __thread wrapper adding a specific destroyer allowing to master what can be done at destruction time.
|
||||
|
||||
CallableThread: A callable `void(thread&)`.
|
||||
|
||||
The default is a `join_if_joinable`.
|
||||
|
||||
|
||||
`std/boost::thread` destructor terminates the program if the __thread is not joinable.
|
||||
This wrapper can be used to join the thread before destroying it seems a natural need.
|
||||
|
||||
[heading Example]
|
||||
|
||||
boost::strict_scoped_thread<> t((boost::thread(F)));
|
||||
|
||||
[section:default_constructor Constructor from a __thread]
|
||||
|
||||
explicit strict_scoped_thread(thread&& t) noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [move the thread to own `t_`]]
|
||||
|
||||
[[Throws:] [Nothing]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:call_constructor Move Constructor from a Callable]
|
||||
|
||||
template <typename F&&, typename ...Args>
|
||||
explicit strict_scoped_thread(F&&, Args&&...);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Construct a internal thread in place.]]
|
||||
|
||||
[[Postconditions:] [`*this.t_` refers to the newly created thread of execution and `this->get_id()!=thread::id()`.]]
|
||||
|
||||
[[Throws:] [Any exception the thread construction can throw.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:destructor Destructor]
|
||||
|
||||
~strict_scoped_thread();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Equivalent to `CallableThread()(t_)`. ]]
|
||||
|
||||
[[Throws:] [Nothing: The `CallableThread()(t_)` should not throw when joining the thread as the scoped variable is on a scope outside the thread function.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:scoped_thread Class `scoped_thread`]
|
||||
|
||||
#include <boost/thread/scoped_thread.hpp>
|
||||
|
||||
template <class CallableThread>
|
||||
class scoped_thread
|
||||
{
|
||||
thread t_; // for exposition purposes only
|
||||
public:
|
||||
scoped_thread() noexcept;
|
||||
scoped_thread(const scoped_thread&) = delete;
|
||||
scoped_thread& operator=(const scoped_thread&) = delete;
|
||||
|
||||
explicit scoped_thread(thread&& th) noexcept;
|
||||
template <typename F&&, typename ...Args>
|
||||
explicit scoped_thread(F&&, Args&&...);
|
||||
|
||||
~scoped_thread();
|
||||
|
||||
// move support
|
||||
scoped_thread(scoped_thread && x) noexcept;
|
||||
scoped_thread& operator=(scoped_thread && x) noexcept;
|
||||
|
||||
void swap(scoped_thread& x) noexcept;
|
||||
|
||||
typedef thread::id id;
|
||||
|
||||
id get_id() const noexcept;
|
||||
|
||||
bool joinable() const noexcept;
|
||||
void join();
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool try_join_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_join_until(const chrono::time_point<Clock, Duration>& t);
|
||||
#endif
|
||||
|
||||
void detach();
|
||||
|
||||
static unsigned hardware_concurrency() noexcept;
|
||||
static unsigned physical_concurrency() noexcept;
|
||||
|
||||
typedef thread::native_handle_type native_handle_type;
|
||||
native_handle_type native_handle();
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
void interrupt();
|
||||
bool interruption_requested() const noexcept;
|
||||
#endif
|
||||
|
||||
|
||||
};
|
||||
|
||||
void swap(scoped_thread& lhs,scoped_thread& rhs) noexcept;
|
||||
|
||||
|
||||
RAI __thread wrapper adding a specific destroyer allowing to master what can be done at destruction time.
|
||||
|
||||
CallableThread: A callable void(thread&).
|
||||
The default is join_if_joinable.
|
||||
|
||||
thread std::thread destructor terminates the program if the thread is not joinable.
|
||||
Having a wrapper that can join the thread before destroying it seems a natural need.
|
||||
|
||||
Remark: `scoped_thread` is not a __thread as __thread is not designed to be derived from as a polymorphic type.
|
||||
|
||||
Anyway `scoped_thread` can be used in most of the contexts a __thread could be used as it has the
|
||||
same non-deprecated interface with the exception of the construction.
|
||||
|
||||
[heading Example]
|
||||
|
||||
boost::scoped_thread<> t((boost::thread(F)));
|
||||
t.interrupt();
|
||||
|
||||
|
||||
[section:default_constructor Default Constructor]
|
||||
|
||||
scoped_thread() noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Constructs a scoped_thread instance that wraps to __not_a_thread__.]]
|
||||
|
||||
[[Postconditions:] [`this->get_id()==thread::id()`]]
|
||||
|
||||
[[Throws:] [Nothing]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move_constructor Move Constructor]
|
||||
|
||||
scoped_thread(scoped_thread&& other) noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Transfers ownership of the scoped_thread managed by `other` (if any) to the newly constructed scoped_thread instance.]]
|
||||
|
||||
[[Postconditions:] [`other.get_id()==thread::id()` and `get_id()` returns the value of `other.get_id()` prior to the construction]]
|
||||
|
||||
[[Throws:] [Nothing]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move_assignment Move assignment operator]
|
||||
|
||||
scoped_thread& operator=(scoped_thread&& other) noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Transfers ownership of the scoped_thread managed by `other` (if
|
||||
any) to `*this`.
|
||||
|
||||
- if defined `BOOST_THREAD_DONT_PROVIDE_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE`: If there was a `scoped_thread` previously associated with `*this` then that `scoped_thread` is detached, DEPRECATED
|
||||
|
||||
- if defined `BOOST_THREAD_PROVIDES_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE`: If the `scoped_thread` is joinable calls to std::terminate.
|
||||
]]
|
||||
|
||||
[[Postconditions:] [`other->get_id()==thread::id()` and `get_id()` returns the value of `other.get_id()` prior to the assignment.]]
|
||||
|
||||
[[Throws:] [Nothing]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:thread_constructor Move Constructor from a __thread]
|
||||
|
||||
scoped_thread(thread&& t);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [move the thread to own `t_`.]]
|
||||
|
||||
[[Postconditions:] [`*this.t_` refers to the newly created thread of execution and `this->get_id()!=thread::id()`.]]
|
||||
|
||||
[[Throws:] [Nothing]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:call_constructor Move Constructor from a Callable]
|
||||
|
||||
template <typename F&&, typename ...Args>
|
||||
explicit scoped_thread(F&&, Args&&...);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Construct a internal thread in place.]]
|
||||
|
||||
[[Postconditions:] [`*this.t_` refers to the newly created thread of execution and `this->get_id()!=thread::id()`.]]
|
||||
|
||||
[[Throws:] [Any exception the thread construction can throw.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:destructor Destructor]
|
||||
|
||||
~scoped_thread();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Equivalent to `CallableThread()(t_)`. ]]
|
||||
|
||||
[[Throws:] [Nothing: The `CallableThread()(t_)` should not throw when joining the thread as the scoped variable is on a scope outside the thread function.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:joinable Member function `joinable()`]
|
||||
|
||||
bool joinable() const noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Returns:] [Equivalent to return t_.joinable().]]
|
||||
|
||||
[[Throws:] [Nothing]]
|
||||
|
||||
]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:join Member function `join()`]
|
||||
|
||||
void join();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Equivalent to t_.join().]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:try_join_for Member function `try_join_for()`]
|
||||
|
||||
template <class Rep, class Period>
|
||||
bool try_join_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Equivalent to return `t_.try_join_for(rel_time)`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:try_join_until Member function `try_join_until()`]
|
||||
|
||||
template <class Clock, class Duration>
|
||||
bool try_join_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Equivalent to return `t_.try_join_until(abs_time)`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
[section:detach Member function `detach()`]
|
||||
|
||||
void detach();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Equivalent to `t_.detach()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:get_id Member function `get_id()`]
|
||||
|
||||
thread::id get_id() const noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Equivalent to return `t_.get_id()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:interrupt Member function `interrupt()`]
|
||||
|
||||
void interrupt();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Equivalent to `t_.interrupt()`.]]
|
||||
|
||||
]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:hardware_concurrency Static member function `hardware_concurrency()`]
|
||||
|
||||
unsigned hardware_concurrency() noexecpt;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Equivalent to return `thread::hardware_concurrency()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:physical_concurrency Static member function `physical_concurrency()`]
|
||||
|
||||
unsigned physical_concurrency() noexecpt;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Equivalent to return `thread::physical_concurrency()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:nativehandle Member function `native_handle()`]
|
||||
|
||||
typedef thread::native_handle_type native_handle_type;
|
||||
native_handle_type native_handle();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Equivalent to return `t_.native_handle()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:swap Member function `swap()`]
|
||||
|
||||
void swap(scoped_thread& other) noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Equivalent `t_.swap(other.t_)`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
[endsect]
|
||||
[section:non_member_swap Non-member function `swap(scoped_thread&,scoped_thread&)`]
|
||||
|
||||
#include <boost/thread/scoped_thread.hpp>
|
||||
|
||||
void swap(scoped_thread& lhs,scoped_thread& rhs) noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [`lhs.swap(rhs)`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
228
doc/shared_mutex_ref.qbk
Normal file
228
doc/shared_mutex_ref.qbk
Normal file
@@ -0,0 +1,228 @@
|
||||
[/
|
||||
(C) Copyright 2007-8 Anthony Williams.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:shared_mutex Class `shared_mutex` -- C++14]
|
||||
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
|
||||
class shared_mutex
|
||||
{
|
||||
public:
|
||||
shared_mutex(shared_mutex const&) = delete;
|
||||
shared_mutex& operator=(shared_mutex const&) = delete;
|
||||
|
||||
shared_mutex();
|
||||
~shared_mutex();
|
||||
|
||||
void lock_shared();
|
||||
bool try_lock_shared();
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
void unlock_shared();
|
||||
|
||||
void lock();
|
||||
bool try_lock();
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
void unlock();
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_DEPRECATED_FEATURES_SINCE_V3_0_0
|
||||
// use upgrade_mutex instead.
|
||||
void lock_upgrade(); // EXTENSION
|
||||
void unlock_upgrade(); // EXTENSION
|
||||
|
||||
void unlock_upgrade_and_lock(); // EXTENSION
|
||||
void unlock_and_lock_upgrade(); // EXTENSION
|
||||
void unlock_and_lock_shared(); // EXTENSION
|
||||
void unlock_upgrade_and_lock_shared(); // EXTENSION
|
||||
#endif
|
||||
|
||||
#if defined BOOST_THREAD_USES_DATETIME
|
||||
bool timed_lock_shared(system_time const& timeout); // DEPRECATED
|
||||
bool timed_lock(system_time const& timeout); // DEPRECATED
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
The class `boost::shared_mutex` provides an implementation of a multiple-reader / single-writer mutex. It implements the
|
||||
__shared_lockable_concept__.
|
||||
|
||||
Multiple concurrent calls to __lock_ref__, __try_lock_ref__, `__try_lock_for()`, `__try_lock_until()`, __timed_lock_ref__, __lock_shared_ref__,
|
||||
`__try_lock_shared_for()`, `__try_lock_shared_until()`, __try_lock_shared_ref__ and __timed_lock_shared_ref__ are permitted.
|
||||
|
||||
Note the the lack of reader-writer priority policies in shared_mutex. This is due to an algorithm credited to Alexander Terekhov which lets the OS decide which thread is the next to get the lock without caring whether a unique lock or shared lock is being sought. This results in a complete lack of reader or writer starvation. It is simply fair.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:upgrade_mutex Class `upgrade_mutex` -- EXTENSION]
|
||||
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
|
||||
class upgrade_mutex
|
||||
{
|
||||
public:
|
||||
upgrade_mutex(upgrade_mutex const&) = delete;
|
||||
upgrade_mutex& operator=(upgrade_mutex const&) = delete;
|
||||
|
||||
upgrade_mutex();
|
||||
~upgrade_mutex();
|
||||
|
||||
void lock_shared();
|
||||
bool try_lock_shared();
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
void unlock_shared();
|
||||
|
||||
void lock();
|
||||
bool try_lock();
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
void unlock();
|
||||
|
||||
void lock_upgrade();
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_upgrade_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_upgrade_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
void unlock_upgrade();
|
||||
|
||||
// Shared <-> Exclusive
|
||||
|
||||
#ifdef BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS
|
||||
bool try_unlock_shared_and_lock();
|
||||
template <class Rep, class Period>
|
||||
bool try_unlock_shared_and_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_unlock_shared_and_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
#endif
|
||||
void unlock_and_lock_shared();
|
||||
|
||||
// Shared <-> Upgrade
|
||||
|
||||
#ifdef BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS
|
||||
bool try_unlock_shared_and_lock_upgrade();
|
||||
template <class Rep, class Period>
|
||||
bool try_unlock_shared_and_lock_upgrade_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_unlock_shared_and_lock_upgrade_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
#endif
|
||||
void unlock_upgrade_and_lock_shared();
|
||||
|
||||
// Upgrade <-> Exclusive
|
||||
|
||||
void unlock_upgrade_and_lock();
|
||||
#if defined(BOOST_THREAD_PLATFORM_PTHREAD)
|
||||
|| defined(BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN)
|
||||
bool try_unlock_upgrade_and_lock();
|
||||
template <class Rep, class Period>
|
||||
bool try_unlock_upgrade_and_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_unlock_upgrade_and_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
#endif
|
||||
void unlock_and_lock_upgrade();
|
||||
};
|
||||
|
||||
The class `boost::upgrade_mutex` provides an implementation of a multiple-reader / single-writer mutex. It implements the
|
||||
__upgrade_lockable_concept__.
|
||||
|
||||
Multiple concurrent calls to __lock_ref__, __try_lock_ref__, `__try_lock_for()`, `__try_lock_until()`, __timed_lock_ref__, __lock_shared_ref__,
|
||||
`__try_lock_shared_for()`, `__try_lock_shared_until()`, __try_lock_shared_ref__ and __timed_lock_shared_ref__ are permitted.
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:null_mutex Class `null_mutex` -- EXTENSION]
|
||||
|
||||
#include <boost/thread/null_mutex.hpp>
|
||||
|
||||
class null_mutex
|
||||
{
|
||||
public:
|
||||
null_mutex(null_mutex const&) = delete;
|
||||
null_mutex& operator=(null_mutex const&) = delete;
|
||||
|
||||
null_mutex();
|
||||
~null_mutex();
|
||||
|
||||
void lock_shared();
|
||||
bool try_lock_shared();
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
#endif
|
||||
void unlock_shared();
|
||||
|
||||
void lock();
|
||||
bool try_lock();
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
#endif
|
||||
void unlock();
|
||||
|
||||
void lock_upgrade();
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_upgrade_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_upgrade_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
#endif
|
||||
void unlock_upgrade();
|
||||
|
||||
// Shared <-> Exclusive
|
||||
|
||||
bool try_unlock_shared_and_lock();
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool try_unlock_shared_and_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_unlock_shared_and_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
#endif
|
||||
void unlock_and_lock_shared();
|
||||
|
||||
// Shared <-> Upgrade
|
||||
|
||||
bool try_unlock_shared_and_lock_upgrade();
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool try_unlock_shared_and_lock_upgrade_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_unlock_shared_and_lock_upgrade_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
#endif
|
||||
void unlock_upgrade_and_lock_shared();
|
||||
|
||||
// Upgrade <-> Exclusive
|
||||
|
||||
void unlock_upgrade_and_lock();
|
||||
bool try_unlock_upgrade_and_lock();
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool try_unlock_upgrade_and_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_unlock_upgrade_and_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
#endif
|
||||
void unlock_and_lock_upgrade();
|
||||
};
|
||||
|
||||
The class `boost::null_mutex` provides a no-op implementation of a multiple-reader / single-writer mutex. It is a model of the
|
||||
__UpgradeLockable concept.
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
1122
doc/sync_queues_ref.qbk
Normal file
1122
doc/sync_queues_ref.qbk
Normal file
File diff suppressed because it is too large
Load Diff
193
doc/sync_streams.qbk
Normal file
193
doc/sync_streams.qbk
Normal file
@@ -0,0 +1,193 @@
|
||||
[/
|
||||
/ Copyright (c) 2013 Vicente J. Botet Escriba
|
||||
/
|
||||
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
|
||||
|
||||
[section:ext_locked_streams Externally Locked Streams - EXPERIMENTAL]
|
||||
|
||||
[warning These features are experimental and subject to change in future versions. There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
|
||||
|
||||
[note These features are based on the [@http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3535.html [*N3535 - C++ Streams Mutex]] C++1y proposal, even if the library proposes al alternative interface.]
|
||||
|
||||
[section:tutorial Tutorial]
|
||||
|
||||
[endsect] [/tutorial]
|
||||
|
||||
[/////////////////////]
|
||||
[section:ref Reference]
|
||||
|
||||
#include <boost/thread/externally_locked_stream.hpp>
|
||||
namespace boost
|
||||
{
|
||||
template <typename Stream, typename RecursiveMutex=recursive_mutex>
|
||||
class externally_locked_stream;
|
||||
template <class Stream, typename RecursiveMutex=recursive_mutex>
|
||||
class stream_guard;
|
||||
template <typename Stream, typename RecursiveMutex>
|
||||
struct is_strict_lock_sur_parole<stream_guard<Stream, RecursiveMutex> > : true_type {};
|
||||
|
||||
// Stream-like operators
|
||||
template <typename Stream, typename RecursiveMutex, typename T>
|
||||
const stream_guard<Stream, RecursiveMutex>& operator<<(const stream_guard<Stream, RecursiveMutex>& lck, T arg);
|
||||
template <typename Stream, typename RecursiveMutex>
|
||||
const stream_guard<Stream, RecursiveMutex>&
|
||||
operator<<(const stream_guard<Stream, RecursiveMutex>& lck, Stream& (*arg)(Stream&));
|
||||
template <typename Stream, typename RecursiveMutex, typename T>
|
||||
const stream_guard<Stream, RecursiveMutex>&
|
||||
operator>>(const stream_guard<Stream, RecursiveMutex>& lck, T& arg);
|
||||
template <typename Stream, typename RecursiveMutex, typename T>
|
||||
stream_guard<Stream, RecursiveMutex>
|
||||
operator<<(externally_locked_stream<Stream, RecursiveMutex>& mtx, T arg);
|
||||
template <typename Stream, typename RecursiveMutex>
|
||||
stream_guard<Stream, RecursiveMutex>
|
||||
operator<<(externally_locked_stream<Stream, RecursiveMutex>& mtx, Stream& (*arg)(Stream&));
|
||||
template <typename Stream, typename RecursiveMutex, typename T>
|
||||
stream_guard<Stream, RecursiveMutex>
|
||||
operator>>(externally_locked_stream<Stream, RecursiveMutex>& mtx, T& arg);
|
||||
}
|
||||
|
||||
[/////////////////////////////////////////]
|
||||
[section:stream_guard Class `stream_guard`]
|
||||
|
||||
#include <boost/thread/externally_locked_stream.hpp>
|
||||
namespace boost
|
||||
{
|
||||
template <class Stream, typename RecursiveMutex=recursive_mutex>
|
||||
class stream_guard
|
||||
{
|
||||
public:
|
||||
typedef typename externally_locked_stream<Stream, RecursiveMutex>::mutex_type mutex_type;
|
||||
|
||||
// Constructors, Assignment and Destructors
|
||||
stream_guard(stream_guard const&) = delete;
|
||||
stream_guard& operator=(stream_guard const&) = delete;
|
||||
stream_guard(externally_locked_stream<Stream, RecursiveMutex>& mtx);
|
||||
stream_guard(externally_locked_stream<Stream, RecursiveMutex>& mtx, adopt_lock_t);
|
||||
stream_guard(stream_guard&& rhs);
|
||||
~stream_guard();
|
||||
|
||||
// Observers
|
||||
bool owns_lock(mutex_type const* l) const BOOST_NOEXCEPT;
|
||||
Stream& get() const;
|
||||
Stream& bypass() const;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
`stream_guard` is a model of __StrictLock.
|
||||
|
||||
[//////////////////////////////////////////////////]
|
||||
[section:constructor `stream_guard(mutex_type & m)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Stores a reference to `m`. Invokes [lock_ref_link `m.lock()`].]]
|
||||
|
||||
[[Throws:] [Any exception thrown by the call to [lock_ref_link `m.lock()`].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[////////////////////////////////////////////////////////////////////////////]
|
||||
[section:constructor_adopt `stream_guard(mutex_type & m,boost::adopt_lock_t)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Precondition:] [The current thread owns a lock on `m` equivalent to one
|
||||
obtained by a call to [lock_ref_link `m.lock()`].]]
|
||||
|
||||
[[Effects:] [Stores a reference to `m`. Takes ownership of the lock state of
|
||||
`m`.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[//////////////////////////////////////////////////////////]
|
||||
[section:move_constructor `stream_guard(stream_guard && m)`]
|
||||
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Stores a reference to `m`. Invokes [lock_ref_link `m.lock()`].]]
|
||||
|
||||
[[Throws:] [Any exception thrown by the call to [lock_ref_link `m.lock()`].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[////////////////////////////////////]
|
||||
[section:destructor `~stream_guard()`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Invokes [unlock_ref_link `m.unlock()`] on the __lockable_concept_type__
|
||||
object passed to the constructor.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
[//////////////////////////////////////////////////////////////////]
|
||||
[section:externally_locked_stream Class `externally_locked_stream `]
|
||||
|
||||
#include <boost/thread/externally_locked_stream.hpp>
|
||||
namespace boost
|
||||
{
|
||||
template <typename Stream, typename RecursiveMutex>
|
||||
class externally_locked_stream: public externally_locked<Stream&, RecursiveMutex>
|
||||
{
|
||||
public:
|
||||
// Constructors, Assignment and Destructors
|
||||
externally_locked_stream(externally_locked_stream const&) = delete;
|
||||
externally_locked_stream& operator=(externally_locked_stream const&) = delete;
|
||||
externally_locked_stream(Stream& stream, RecursiveMutex& mtx);
|
||||
|
||||
// Modifiers
|
||||
stream_guard<Stream, RecursiveMutex> hold();
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
`externally_locked_stream` cloaks a reference to an stream of type `Stream`, and actually
|
||||
provides full access to that object through the `get` member functions, provided you
|
||||
pass a reference to a strict lock object.
|
||||
|
||||
|
||||
[////////////////////////////////////////////////////////////////////////]
|
||||
[section:constructor `externally_locked_stream(Stream&, RecursiveMutex&)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Constructs an externally locked object storing the cloaked reference object and its locking mutex.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[/////////////////////]
|
||||
[section:hold `hold()`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Returns:] [A stream_guard which will hold the mutex during it lifetime .]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[endsect] [/ref]
|
||||
|
||||
[endsect] [/Externally Locked Streams]
|
||||
64
doc/sync_tutorial.qbk
Normal file
64
doc/sync_tutorial.qbk
Normal file
@@ -0,0 +1,64 @@
|
||||
[/
|
||||
(C) Copyright 2012 Vicente J. Botet Escriba.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:tutorial Tutorial]
|
||||
|
||||
[@http://home.roadrunner.com/~hinnant/mutexes/locking.html Handling mutexes in C++] is an excellent tutorial. You need just replace std and ting by boost.
|
||||
|
||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2406.html Mutex, Lock, Condition Variable Rationale] adds rationale for the design decisions made for mutexes, locks and condition variables.
|
||||
|
||||
|
||||
In addition to the C++11 standard locks, Boost.Thread provides other locks and some utilities that help the user to make their code thread-safe.
|
||||
|
||||
[include internal_locking.qbk]
|
||||
|
||||
[include external_locking.qbk]
|
||||
|
||||
[section:with Executing Around a Function]
|
||||
|
||||
In particular, the library provides a way to lock around the execution of a function.
|
||||
|
||||
template <class Lockable, class Function, class... Args>
|
||||
auto with_lock_guard(
|
||||
Lockable& m,
|
||||
Function&& func,
|
||||
Args&&... args
|
||||
) -> decltype(func(boost::forward<Args>(args)...)) {
|
||||
boost::lock_guard<Lockable> lock(m);
|
||||
return func(boost::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
that can be used with regular functions:
|
||||
|
||||
int func(int, int&);
|
||||
//...
|
||||
boost::mutex m;
|
||||
int a;
|
||||
int result = boost::with_lock_guard(m, func, 1, boost::ref(a));
|
||||
|
||||
with boost::bind:
|
||||
|
||||
int result = boost::with_lock_guard(
|
||||
m, boost::bind(func, 2, boost::ref(a))
|
||||
);
|
||||
|
||||
or with lambda expression:
|
||||
|
||||
int a;
|
||||
int result = boost::with_lock_guard(
|
||||
m,
|
||||
[&a](int x) {
|
||||
// this scope is protected by mutex m
|
||||
a = 3;
|
||||
return x + 4;
|
||||
},
|
||||
5
|
||||
);
|
||||
|
||||
[endsect] [/ With]
|
||||
|
||||
[endsect] [/ Tutorial]
|
||||
147
doc/synchronized_value.qbk
Normal file
147
doc/synchronized_value.qbk
Normal file
@@ -0,0 +1,147 @@
|
||||
[/
|
||||
/ Copyright (c) 2013 Vicente J. Botet Escriba
|
||||
/
|
||||
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
|
||||
|
||||
[section:synchronized_valuesxxx Synchronized Values - EXPERIMENTAL]
|
||||
|
||||
[warning These features are experimental and subject to change in future versions. There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
|
||||
|
||||
[section:tutorial Tutorial]
|
||||
|
||||
|
||||
[note This tutorial is an adaptation of the paper of Anthony Williams "Enforcing Correct Mutex Usage with Synchronized Values" to the Boost library.]
|
||||
|
||||
[section The Problem with Mutexes]
|
||||
|
||||
The key problem with protecting shared data with a mutex is that there is no easy way to associate the mutex with the data. It is thus relatively easy to accidentally write code that fails to lock the right mutex - or even locks the wrong mutex - and the compiler will not help you.
|
||||
|
||||
|
||||
std::mutex m1;
|
||||
int value1;
|
||||
std::mutex m2;
|
||||
int value2;
|
||||
|
||||
int readValue1()
|
||||
{
|
||||
boost::lock_guard<boost::mutex> lk(m1);
|
||||
return value1;
|
||||
}
|
||||
int readValue2()
|
||||
{
|
||||
boost::lock_guard<boost::mutex> lk(m1); // oops: wrong mutex
|
||||
return value2;
|
||||
}
|
||||
|
||||
Moreover, managing the mutex lock also clutters the source code, making it harder to see what is really going on.
|
||||
|
||||
The use of synchronized_value solves both these problems - the mutex is intimately tied to the value, so you cannot access it without a lock, and yet access semantics are still straightforward. For simple accesses, synchronized_value behaves like a pointer-to-T; for example:
|
||||
|
||||
|
||||
boost::synchronized_value<std::string> value3;
|
||||
std::string readValue3()
|
||||
{
|
||||
return *value3;
|
||||
}
|
||||
void setValue3(std::string const& newVal)
|
||||
{
|
||||
*value3=newVal;
|
||||
}
|
||||
void appendToValue3(std::string const& extra)
|
||||
{
|
||||
value3->append(extra);
|
||||
}
|
||||
|
||||
Both forms of pointer dereference return a proxy object rather than a real reference, to ensure that the lock on the mutex is held across the assignment or method call, but this is transparent to the user.
|
||||
|
||||
[endsect] [/The Problem with Mutexes]
|
||||
|
||||
[section Beyond Simple Accesses]
|
||||
|
||||
The pointer-like semantics work very well for simple accesses such as assignment and calls to member functions. However, sometimes you need to perform an operation that requires multiple accesses under protection of the same lock, and that's what the synchronize() method provides.
|
||||
|
||||
By calling synchronize() you obtain an strict_lock_ptr object that holds a lock on the mutex protecting the data, and which can be used to access the protected data. The lock is held until the strict_lock_ptr object is destroyed, so you can safely perform multi-part operations. The strict_lock_ptr object also acts as a pointer-to-T, just like synchronized_value does, but this time the lock is already held. For example, the following function adds a trailing slash to a path held in a synchronized_value. The use of the strict_lock_ptr object ensures that the string hasn't changed in between the query and the update.
|
||||
|
||||
void addTrailingSlashIfMissing(boost::synchronized_value<std::string> & path)
|
||||
{
|
||||
boost::strict_lock_ptr<std::string> u=path.synchronize();
|
||||
|
||||
if(u->empty() || (*u->rbegin()!='/'))
|
||||
{
|
||||
*u+='/';
|
||||
}
|
||||
}
|
||||
|
||||
[endsect] [/Beyond Simple Accesses]
|
||||
|
||||
[section Operations Across Multiple Objects]
|
||||
|
||||
Though synchronized_value works very well for protecting a single object of type T, nothing that we've seen so far solves the problem of operations that require atomic access to multiple objects unless those objects can be combined within a single structure protected by a single mutex.
|
||||
|
||||
One way to protect access to two synchronized_value objects is to construct a strict_lock_ptr for each object and use those to access the respective protected values; for instance:
|
||||
|
||||
synchronized_value<std::queue<MessageType> > q1,q2;
|
||||
void transferMessage()
|
||||
{
|
||||
strict_lock_ptr<std::queue<MessageType> > u1 = q1.synchronize();
|
||||
strict_lock_ptr<std::queue<MessageType> > u2 = q2.synchronize();
|
||||
|
||||
if(!u1->empty())
|
||||
{
|
||||
u2->push_back(u1->front());
|
||||
u1->pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
This works well in some scenarios, but not all -- if the same two objects are updated together in different sections of code then you need to take care to ensure that the strict_lock_ptr objects are constructed in the same sequence in all cases, otherwise you have the potential for deadlock. This is just the same as when acquiring any two mutexes.
|
||||
|
||||
In order to be able to use the dead-lock free lock algorithms we need to use instead unique_lock_ptr, which is Lockable.
|
||||
|
||||
synchronized_value<std::queue<MessageType> > q1,q2;
|
||||
void transferMessage()
|
||||
{
|
||||
unique_lock_ptr<std::queue<MessageType> > u1 = q1.unique_synchronize(boost::defer_lock);
|
||||
unique_lock_ptr<std::queue<MessageType> > u2 = q2.unique_synchronize(boost::defer_lock);
|
||||
boost::lock(u1,u2); // dead-lock free algorithm
|
||||
|
||||
if(!u1->empty())
|
||||
{
|
||||
u2->push_back(u1->front());
|
||||
u1->pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
While the preceding takes care of dead-lock, the access to the synchronized_value via unique_lock_ptr requires a lock that is not forced by the interface.
|
||||
An alternative on compilers providing a standard library that supports movable std::tuple is to use the free synchronize function, which will lock all the mutexes associated to the synchronized values and return a tuple os strict_lock_ptr.
|
||||
|
||||
synchronized_value<std::queue<MessageType> > q1,q2;
|
||||
void transferMessage()
|
||||
{
|
||||
auto lks = synchronize(u1,u2); // dead-lock free algorithm
|
||||
|
||||
if(!std::get<1>(lks)->empty())
|
||||
{
|
||||
std::get<2>(lks)->push_back(u1->front());
|
||||
std::get<1>(lks)->pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[endsect] [/Operations Across Multiple Objects]
|
||||
|
||||
[section Value semantics]
|
||||
|
||||
synchronized_value has value semantics even if the syntax lets is close to a pointer (this is just because we are unable to define smart references).
|
||||
|
||||
[endsect] [/Value semantics]
|
||||
|
||||
|
||||
[endsect] [/tutorial]
|
||||
|
||||
[include synchronized_value_ref.qbk]
|
||||
|
||||
[endsect] [/Synchronized values]
|
||||
|
||||
415
doc/synchronized_value_ref.qbk
Normal file
415
doc/synchronized_value_ref.qbk
Normal file
@@ -0,0 +1,415 @@
|
||||
[/
|
||||
/ Copyright (c) 2013 Vicente J. Botet Escriba
|
||||
/
|
||||
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
|
||||
[section:synchronized_value_ref Reference ]
|
||||
|
||||
|
||||
#include <boost/thread/synchronized_value.hpp>
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template<typename T, typename Lockable = mutex>
|
||||
class synchronized_value;
|
||||
|
||||
// Specialized swap algorithm
|
||||
template <typename T, typename L>
|
||||
void swap(synchronized_value<T,L> & lhs, synchronized_value<T,L> & rhs);
|
||||
template <typename T, typename L>
|
||||
void swap(synchronized_value<T,L> & lhs, T & rhs);
|
||||
template <typename T, typename L>
|
||||
void swap(T & lhs, synchronized_value<T,L> & rhs);
|
||||
|
||||
// Hash support
|
||||
template<typename T, typename L>
|
||||
struct hash<synchronized_value<T,L> >;
|
||||
|
||||
// Comparison
|
||||
template <typename T, typename L>
|
||||
bool operator==(synchronized_value<T,L> const&lhs, synchronized_value<T,L> const& rhs)
|
||||
template <typename T, typename L>
|
||||
bool operator!=(synchronized_value<T,L> const&lhs, synchronized_value<T,L> const& rhs)
|
||||
template <typename T, typename L>
|
||||
bool operator<(synchronized_value<T,L> const&lhs, synchronized_value<T,L> const& rhs)
|
||||
template <typename T, typename L>
|
||||
bool operator<=(synchronized_value<T,L> const&lhs, synchronized_value<T,L> const& rhs)
|
||||
template <typename T, typename L>
|
||||
bool operator>(synchronized_value<T,L> const&lhs, synchronized_value<T,L> const& rhs)
|
||||
template <typename T, typename L>
|
||||
bool operator>=(synchronized_value<T,L> const&lhs, synchronized_value<T,L> const& rhs)
|
||||
|
||||
// Comparison with T
|
||||
template <typename T, typename L>
|
||||
bool operator==(T const& lhs, synchronized_value<T,L> const&rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator!=(T const& lhs, synchronized_value<T,L> const&rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator<(T const& lhs, synchronized_value<T,L> const&rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator<=(T const& lhs, synchronized_value<T,L> const&rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator>(T const& lhs, synchronized_value<T,L> const&rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator>=(T const& lhs, synchronized_value<T,L> const&rhs);
|
||||
|
||||
template <typename T, typename L>
|
||||
bool operator==(synchronized_value<T,L> const& lhs, T const& rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator!=(synchronized_value<T,L> const& lhs, T const& rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator<(synchronized_value<T,L> const& lhs, T const& rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator<=(synchronized_value<T,L> const& lhs, T const& rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator>(synchronized_value<T,L> const& lhs, T const& rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator>=(synchronized_value<T,L> const& lhs, T const& rhs);
|
||||
|
||||
#if ! defined(BOOST_THREAD_NO_SYNCHRONIZE)
|
||||
template <typename ...SV>
|
||||
std::tuple<typename synchronized_value_strict_lock_ptr<SV>::type ...> synchronize(SV& ...sv);
|
||||
#endif
|
||||
}
|
||||
|
||||
[section:synchronized_value Class `synchronized_value`]
|
||||
|
||||
#include <boost/thread/synchronized_value.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template<typename T, typename Lockable = mutex>
|
||||
class synchronized_value
|
||||
{
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef Lockable mutex_type;
|
||||
|
||||
synchronized_value() noexept(is_nothrow_default_constructible<T>::value);
|
||||
synchronized_value(T const& other) noexept(is_nothrow_copy_constructible<T>::value);
|
||||
synchronized_value(T&& other) noexept(is_nothrow_move_constructible<T>::value);
|
||||
synchronized_value(synchronized_value const& rhs);
|
||||
synchronized_value(synchronized_value&& other);
|
||||
|
||||
// mutation
|
||||
synchronized_value& operator=(synchronized_value const& rhs);
|
||||
synchronized_value& operator=(value_type const& val);
|
||||
void swap(synchronized_value & rhs);
|
||||
void swap(value_type & rhs);
|
||||
|
||||
//observers
|
||||
T get() const;
|
||||
#if ! defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
|
||||
explicit operator T() const;
|
||||
#endif
|
||||
|
||||
strict_lock_ptr<T,Lockable> operator->();
|
||||
const_strict_lock_ptr<T,Lockable> operator->() const;
|
||||
strict_lock_ptr<T,Lockable> synchronize();
|
||||
const_strict_lock_ptr<T,Lockable> synchronize() const;
|
||||
|
||||
deref_value operator*();;
|
||||
const_deref_value operator*() const;
|
||||
|
||||
private:
|
||||
T value_; // for exposition only
|
||||
mutable mutex_type mtx_; // for exposition only
|
||||
};
|
||||
}
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`Lockable` is `Lockable`.]]
|
||||
|
||||
]
|
||||
|
||||
|
||||
[section:constructor `synchronized_value()`]
|
||||
|
||||
synchronized_value() noexept(is_nothrow_default_constructible<T>::value);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `DefaultConstructible`.]]
|
||||
[[Effects:] [Default constructs the cloaked value_type]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:constructor_vt `synchronized_value(T const&)`]
|
||||
|
||||
synchronized_value(T const& other) noexept(is_nothrow_copy_constructible<T>::value);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `CopyConstructible`.]]
|
||||
[[Effects:] [Copy constructs the cloaked value_type using the parameter `other`]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type(other)`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:copy_cons `synchronized_value(synchronized_value const&)`]
|
||||
|
||||
synchronized_value(synchronized_value const& rhs);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `DefaultConstructible` and `Assignable`.]]
|
||||
[[Effects:] [Assigns the value on a scope protected by the mutex of the rhs. The mutex is not copied.]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type()` or `value_type& operator=(value_type&)` or `mtx_.lock()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move_vt `synchronized_value(T&&)`]
|
||||
|
||||
synchronized_value(T&& other) noexept(is_nothrow_move_constructible<T>::value);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `CopyMovable `.]]
|
||||
[[Effects:] [Move constructs the cloaked value_type]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type(value_type&&)`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move `synchronized_value(synchronized_value&&)`]
|
||||
|
||||
synchronized_value(synchronized_value&& other);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `CopyMovable `.]]
|
||||
[[Effects:] [Move constructs the cloaked value_type]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type(value_type&&)` or `mtx_.lock()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:assign `operator=(synchronized_value const&)`]
|
||||
|
||||
synchronized_value& operator=(synchronized_value const& rhs);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `Assignale`.]]
|
||||
[[Effects:] [Copies the underlying value on a scope protected by the two mutexes. The mutex is not copied. The locks are acquired avoiding deadlock. For example, there is no problem if one thread assigns `a = b` and the other assigns `b = a`.]]
|
||||
[[Return:] [`*this`]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type& operator(value_type const&)` or `mtx_.lock()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:assign_vt `operator=(T const&)`]
|
||||
|
||||
synchronized_value& operator=(value_type const& val);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `Assignale`.]]
|
||||
[[Effects:] [Copies the value on a scope protected by the mutex.]]
|
||||
[[Return:] [`*this`]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type& operator(value_type const&)` or `mtx_.lock()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:get `get() const`]
|
||||
|
||||
T get() const;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `CopyConstructible`.]]
|
||||
[[Return:] [`A copy of the protected value obtained on a scope protected by the mutex.`]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type(value_type const&)` or `mtx_.lock()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:T `operator T() const`]
|
||||
|
||||
#if ! defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
|
||||
explicit operator T() const;
|
||||
#endif
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `CopyConstructible`.]]
|
||||
[[Return:] [`A copy of the protected value obtained on a scope protected by the mutex.`]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type(value_type const&)` or `mtx_.lock()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:swap `swap(synchronized_value&)`]
|
||||
|
||||
void swap(synchronized_value & rhs);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `Assignale`.]]
|
||||
[[Effects:] [Swaps the data on a scope protected by both mutex. Both mutex are acquired to avoid dead-lock. The mutexes are not swapped.]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `swap(value_, rhs.value)` or `mtx_.lock()` or `rhs_.mtx_.lock()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:swap_vt `swap(synchronized_value&)`]
|
||||
|
||||
void swap(value_type & rhs);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `Swapable`.]]
|
||||
[[Effects:] [Swaps the data on a scope protected by both mutex. Both mutex are acquired to avoid dead-lock. The mutexes are not swapped.]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `swap(value_, rhs)` or `mtx_.lock()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:indir `operator->()`]
|
||||
|
||||
strict_lock_ptr<T,Lockable> operator->();
|
||||
|
||||
|
||||
Essentially calling a method `obj->foo(x, y, z)` calls the method `foo(x, y, z)` inside a critical section as long-lived as the call itself.
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Return:] [`A strict_lock_ptr<>.`]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:indir_const `operator->() const`]
|
||||
|
||||
const_strict_lock_ptr<T,Lockable> operator->() const;
|
||||
|
||||
|
||||
If the `synchronized_value` object involved is const-qualified, then you'll only be able to call const methods
|
||||
through `operator->`. So, for example, `vec->push_back("xyz")` won't work if `vec` were const-qualified.
|
||||
The locking mechanism capitalizes on the assumption that const methods don't modify their underlying data.
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Return:] [`A const_strict_lock_ptr <>.`]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:synchronize `synchronize()`]
|
||||
|
||||
strict_lock_ptr<T,Lockable> synchronize();
|
||||
|
||||
The synchronize() factory make easier to lock on a scope. As discussed, `operator->` can only lock over the duration of a call, so it is insufficient for complex operations. With `synchronize()` you get to lock the object in a scoped and to directly access the object inside that scope.
|
||||
|
||||
[*Example:]
|
||||
|
||||
void fun(synchronized_value<vector<int>> & vec) {
|
||||
auto vec2=vec.synchronize();
|
||||
vec2.push_back(42);
|
||||
assert(vec2.back() == 42);
|
||||
}
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Return:] [`A strict_lock_ptr <>.`]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:synchronize_const `synchronize() const`]
|
||||
|
||||
const_strict_lock_ptr<T,Lockable> synchronize() const;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Return:] [`A const_strict_lock_ptr <>.`]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:deref `operator*()`]
|
||||
|
||||
deref_value operator*();;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Return:] [`A an instance of a class that locks the mutex on construction and unlocks it on destruction and provides implicit conversion to a reference to the protected value.`]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:deref_const `operator*() const`]
|
||||
|
||||
const_deref_value operator*() const;
|
||||
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Return:] [`A an instance of a class that locks the mutex on construction and unlocks it on destruction and provides implicit conversion to a constant reference to the protected value.`]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
|
||||
[endsect]
|
||||
[section:synchronize Non-Member Function `synchronize`]
|
||||
|
||||
#include <boost/thread/synchronized_value.hpp>
|
||||
namespace boost
|
||||
{
|
||||
#if ! defined(BOOST_THREAD_NO_SYNCHRONIZE)
|
||||
template <typename ...SV>
|
||||
std::tuple<typename synchronized_value_strict_lock_ptr<SV>::type ...> synchronize(SV& ...sv);
|
||||
#endif
|
||||
}
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
@@ -1,270 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/thread.hpp"
|
||||
last-revision="$Date$">
|
||||
<namespace name="boost">
|
||||
<class name="thread">
|
||||
<purpose>
|
||||
<para>The <classname>thread</classname> class represents threads of
|
||||
execution, and provides the functionality to create and manage
|
||||
threads within the &Boost.Thread; library. See
|
||||
<xref linkend="thread.glossary"/> for a precise description of
|
||||
<link linkend="thread.glossary.thread">thread of execution</link>,
|
||||
and for definitions of threading-related terms and of thread states such as
|
||||
<link linkend="thread.glossary.thread-state">blocked</link>.</para>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<para>A <link linkend="thread.glossary.thread">thread of execution</link>
|
||||
has an initial function. For the program's initial thread, the initial
|
||||
function is <code>main()</code>. For other threads, the initial
|
||||
function is <code>operator()</code> of the function object passed to
|
||||
the <classname>thread</classname> object's constructor.</para>
|
||||
|
||||
<para>A thread of execution is said to be "finished"
|
||||
or to have "finished execution" when its initial function returns or
|
||||
is terminated. This includes completion of all thread cleanup
|
||||
handlers, and completion of the normal C++ function return behaviors,
|
||||
such as destruction of automatic storage (stack) objects and releasing
|
||||
any associated implementation resources.</para>
|
||||
|
||||
<para>A thread object has an associated state which is either
|
||||
"joinable" or "non-joinable".</para>
|
||||
|
||||
<para>Except as described below, the policy used by an implementation
|
||||
of &Boost.Thread; to schedule transitions between thread states is
|
||||
unspecified.</para>
|
||||
|
||||
<para><note>Just as the lifetime of a file may be different from the
|
||||
lifetime of an <code>iostream</code> object which represents the file, the lifetime
|
||||
of a thread of execution may be different from the
|
||||
<classname>thread</classname> object which represents the thread of
|
||||
execution. In particular, after a call to <code>join()</code>,
|
||||
the thread of execution will no longer exist even though the
|
||||
<classname>thread</classname> object continues to exist until the
|
||||
end of its normal lifetime. The converse is also possible; if
|
||||
a <classname>thread</classname> object is destroyed without
|
||||
<code>join()</code> first having been called, the thread of execution
|
||||
continues until its initial function completes.</note></para>
|
||||
</description>
|
||||
|
||||
<inherit access="private">
|
||||
<type><classname>boost::noncopyable</classname></type>
|
||||
<purpose>Exposition only</purpose>
|
||||
</inherit>
|
||||
|
||||
<constructor>
|
||||
<effects>Constructs a <classname>thread</classname> object
|
||||
representing the current thread of execution.</effects>
|
||||
|
||||
<postconditions><code>*this</code> is non-joinable.</postconditions>
|
||||
|
||||
<notes><emphasis role="bold">Danger:</emphasis>
|
||||
<code>*this</code> is valid only within the current thread.</notes>
|
||||
</constructor>
|
||||
|
||||
<constructor specifiers="explicit">
|
||||
<parameter name="threadfunc">
|
||||
<paramtype>const boost::function0<void>&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<effects>
|
||||
Starts a new thread of execution and constructs a
|
||||
<classname>thread</classname> object representing it.
|
||||
Copies <code>threadfunc</code> (which in turn copies
|
||||
the function object wrapped by <code>threadfunc</code>)
|
||||
to an internal location which persists for the lifetime
|
||||
of the new thread of execution. Calls <code>operator()</code>
|
||||
on the copy of the <code>threadfunc</code> function object
|
||||
in the new thread of execution.
|
||||
</effects>
|
||||
|
||||
<postconditions><code>*this</code> is joinable.</postconditions>
|
||||
|
||||
<throws><code>boost::thread_resource_error</code> if a new thread
|
||||
of execution cannot be started.</throws>
|
||||
</constructor>
|
||||
|
||||
<destructor>
|
||||
<effects>Destroys <code>*this</code>. The actual thread of
|
||||
execution may continue to execute after the
|
||||
<classname>thread</classname> object has been destroyed.
|
||||
</effects>
|
||||
|
||||
<notes>If <code>*this</code> is joinable the actual thread
|
||||
of execution becomes "detached". Any resources used
|
||||
by the thread will be reclaimed when the thread of execution
|
||||
completes. To ensure such a thread of execution runs to completion
|
||||
before the <classname>thread</classname> object is destroyed, call
|
||||
<code>join()</code>.</notes>
|
||||
</destructor>
|
||||
|
||||
<method-group name="comparison">
|
||||
<method name="operator==" cv="const">
|
||||
<type>bool</type>
|
||||
|
||||
<parameter name="rhs">
|
||||
<type>const thread&</type>
|
||||
</parameter>
|
||||
|
||||
<requires>The thread is non-terminated or <code>*this</code>
|
||||
is joinable.</requires>
|
||||
|
||||
<returns><code>true</code> if <code>*this</code> and
|
||||
<code>rhs</code> represent the same thread of
|
||||
execution.</returns>
|
||||
</method>
|
||||
|
||||
<method name="operator!=" cv="const">
|
||||
<type>bool</type>
|
||||
|
||||
<parameter name="rhs">
|
||||
<type>const thread&</type>
|
||||
</parameter>
|
||||
|
||||
<requires>The thread is non-terminated or <code>*this</code>
|
||||
is joinable.</requires>
|
||||
|
||||
<returns><code>!(*this==rhs)</code>.</returns>
|
||||
</method>
|
||||
</method-group>
|
||||
|
||||
<method-group name="modifier">
|
||||
<method name="join">
|
||||
<type>void</type>
|
||||
|
||||
<requires><code>*this</code> is joinable.</requires>
|
||||
|
||||
<effects>The current thread of execution blocks until the
|
||||
initial function of the thread of execution represented by
|
||||
<code>*this</code> finishes and all resources are
|
||||
reclaimed.</effects>
|
||||
|
||||
<postcondition><code>*this</code> is non-joinable.</postcondition>
|
||||
|
||||
<notes>If <code>*this == thread()</code> the result is
|
||||
implementation-defined. If the implementation doesn't
|
||||
detect this the result will be
|
||||
<link linkend="thread.glossary.deadlock">deadlock</link>.
|
||||
</notes>
|
||||
</method>
|
||||
</method-group>
|
||||
|
||||
<method-group name="static">
|
||||
<method name="sleep" specifiers="static">
|
||||
<type>void</type>
|
||||
|
||||
<parameter name="xt">
|
||||
<paramtype>const <classname>xtime</classname>&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<effects>The current thread of execution blocks until
|
||||
<code>xt</code> is reached.</effects>
|
||||
</method>
|
||||
|
||||
<method name="yield" specifiers="static">
|
||||
<type>void</type>
|
||||
|
||||
<effects>The current thread of execution is placed in the
|
||||
<link linkend="thread.glossary.thread-state">ready</link>
|
||||
state.</effects>
|
||||
|
||||
<notes>
|
||||
<simpara>Allow the current thread to give up the rest of its
|
||||
time slice (or other scheduling quota) to another thread.
|
||||
Particularly useful in non-preemptive implementations.</simpara>
|
||||
</notes>
|
||||
</method>
|
||||
</method-group>
|
||||
</class>
|
||||
|
||||
<class name="thread_group">
|
||||
<purpose>
|
||||
The <classname>thread_group</classname> class provides a container
|
||||
for easy grouping of threads to simplify several common thread
|
||||
creation and management idioms.
|
||||
</purpose>
|
||||
|
||||
<inherit access="private">
|
||||
<type><classname>boost::noncopyable</classname></type>
|
||||
<purpose>Exposition only</purpose>
|
||||
</inherit>
|
||||
|
||||
|
||||
<constructor>
|
||||
<effects>Constructs an empty <classname>thread_group</classname>
|
||||
container.</effects>
|
||||
</constructor>
|
||||
|
||||
<destructor>
|
||||
<effects>Destroys each contained thread object. Destroys <code>*this</code>.</effects>
|
||||
|
||||
<notes>Behavior is undefined if another thread references
|
||||
<code>*this </code> during the execution of the destructor.
|
||||
</notes>
|
||||
</destructor>
|
||||
|
||||
<method-group name="modifier">
|
||||
<method name="create_thread">
|
||||
<type><classname>thread</classname>*</type>
|
||||
|
||||
<parameter name="threadfunc">
|
||||
<paramtype>const boost::function0<void>&</paramtype>
|
||||
</parameter>
|
||||
|
||||
<effects>Creates a new <classname>thread</classname> object
|
||||
that executes <code>threadfunc</code> and adds it to the
|
||||
<code>thread_group</code> container object's list of managed
|
||||
<classname>thread</classname> objects.</effects>
|
||||
|
||||
<returns>Pointer to the newly created
|
||||
<classname>thread</classname> object.</returns>
|
||||
</method>
|
||||
|
||||
<method name="add_thread">
|
||||
<type>void</type>
|
||||
|
||||
<parameter name="thrd">
|
||||
<paramtype><classname>thread</classname>*</paramtype>
|
||||
</parameter>
|
||||
|
||||
<effects>Adds <code>thrd</code> to the
|
||||
<classname>thread_group</classname> object's list of managed
|
||||
<classname>thread</classname> objects. The <code>thrd</code>
|
||||
object must have been allocated via <code>operator new</code> and will
|
||||
be deleted when the group is destroyed.</effects>
|
||||
</method>
|
||||
|
||||
<method name="remove_thread">
|
||||
<type>void</type>
|
||||
|
||||
<parameter name="thrd">
|
||||
<paramtype><classname>thread</classname>*</paramtype>
|
||||
</parameter>
|
||||
|
||||
<effects>Removes <code>thread</code> from <code>*this</code>'s
|
||||
list of managed <classname>thread</classname> objects.</effects>
|
||||
|
||||
<throws><emphasis role="bold">???</emphasis> if
|
||||
<code>thrd</code> is not in <code>*this</code>'s list
|
||||
of managed <classname>thread</classname> objects.</throws>
|
||||
</method>
|
||||
|
||||
<method name="join_all">
|
||||
<type>void</type>
|
||||
|
||||
<effects>Calls <code>join()</code> on each of the managed
|
||||
<classname>thread</classname> objects.</effects>
|
||||
</method>
|
||||
</method-group>
|
||||
</class>
|
||||
</namespace>
|
||||
</header>
|
||||
263
doc/thread.qbk
Normal file
263
doc/thread.qbk
Normal file
@@ -0,0 +1,263 @@
|
||||
[/
|
||||
(C) Copyright 2008-11 Anthony Williams
|
||||
(C) Copyright 2011-12 Vicente J. Botet Escriba
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[library Thread
|
||||
[quickbook 1.5]
|
||||
[version 4.4.0]
|
||||
[authors [Williams, Anthony] [Botet Escriba, Vicente J.]]
|
||||
[copyright 2007-11 Anthony Williams]
|
||||
[copyright 2011-14 Vicente J. Botet Escriba]
|
||||
[purpose C++ Library for launching threads and synchronizing data between them]
|
||||
[category text]
|
||||
[license
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
[@http://www.boost.org/LICENSE_1_0.txt])
|
||||
]
|
||||
]
|
||||
|
||||
[template lockable_concept_link[link_text] [link thread.synchronization.mutex_concepts.lockable [link_text]]]
|
||||
[def __lockable_concept__ [lockable_concept_link `Lockable` concept]]
|
||||
[def __lockable_concept_type__ [lockable_concept_link `Lockable`]]
|
||||
[def __BasicLockable [link thread.synchronization.mutex_concepts.basic_lockable `BasicLockable`]]
|
||||
[def __Lockable [link thread.synchronization.mutex_concepts.lockable `Lockable`]]
|
||||
[def __TimedLockable [link thread.synchronization.mutex_concepts.timed_lockable `TimedLockable`]]
|
||||
[def __SharedLockable [link thread.synchronization.mutex_concepts.shared_lockable `SharedLockable`]]
|
||||
[def __UpgradeLockable [link thread.synchronization.mutex_concepts.upgrade_lockable `UpgradeLockable`]]
|
||||
|
||||
[template timed_lockable_concept_link[link_text] [link thread.synchronization.mutex_concepts.timed_lockable [link_text]]]
|
||||
[def __timed_lockable_concept__ [timed_lockable_concept_link `TimedLockable` concept]]
|
||||
[def __timed_lockable_concept_type__ [timed_lockable_concept_link `TimedLockable`]]
|
||||
|
||||
[template shared_lockable_concept_link[link_text] [link thread.synchronization.mutex_concepts.shared_lockable [link_text]]]
|
||||
[def __shared_lockable_concept__ [shared_lockable_concept_link `SharedLockable` concept]]
|
||||
[def __shared_lockable_concept_type__ [shared_lockable_concept_link `SharedLockable`]]
|
||||
|
||||
[template upgrade_lockable_concept_link[link_text] [link thread.synchronization.mutex_concepts.upgrade_lockable [link_text]]]
|
||||
[def __upgrade_lockable_concept__ [upgrade_lockable_concept_link `UpgradeLockable` concept]]
|
||||
[def __upgrade_lockable_concept_type__ [upgrade_lockable_concept_link `UpgradeLockable`]]
|
||||
|
||||
|
||||
[template lock_ref_link[link_text] [link thread.synchronization.mutex_concepts.basic_lockable.lock [link_text]]]
|
||||
[def __lock_ref__ [lock_ref_link `lock()`]]
|
||||
[def __lock [link thread.synchronization.mutex_concepts.basic_lockable.lock `lock`]]
|
||||
|
||||
[template lock_multiple_ref_link[link_text] [link thread.synchronization.lock_functions.lock_multiple [link_text]]]
|
||||
[def __lock_multiple_ref__ [lock_multiple_ref_link `lock()`]]
|
||||
|
||||
[template try_lock_multiple_ref_link[link_text] [link thread.synchronization.lock_functions.try_lock_multiple [link_text]]]
|
||||
[def __try_lock_multiple_ref__ [try_lock_multiple_ref_link `try_lock()`]]
|
||||
|
||||
[template unlock_ref_link[link_text] [link thread.synchronization.mutex_concepts.basic_lockable.unlock [link_text]]]
|
||||
[def __unlock_ref__ [unlock_ref_link `unlock()`]]
|
||||
[def __unlock [link thread.synchronization.mutex_concepts.basic_lockable.unlock `unlock`]]
|
||||
|
||||
[template try_lock_ref_link[link_text] [link thread.synchronization.mutex_concepts.lockable.try_lock [link_text]]]
|
||||
[def __try_lock_ref__ [try_lock_ref_link `try_lock()`]]
|
||||
[def __try_lock [link thread.synchronization.mutex_concepts.lockable.try_lock `try_lock`]]
|
||||
|
||||
[template timed_lock_ref_link[link_text] [link thread.synchronization.mutex_concepts.timed_lockable.timed_lock [link_text]]]
|
||||
[def __timed_lock_ref__ [timed_lock_ref_link `timed_lock()`]]
|
||||
[def __timed_lock [link thread.synchronization.mutex_concepts.timed_lockable.timed_lock `timed_lock`]]
|
||||
|
||||
[def __try_lock_for [link thread.synchronization.mutex_concepts.timed_lockable.try_lock_for `try_lock_for`]]
|
||||
[def __try_lock_until [link thread.synchronization.mutex_concepts.timed_lockable.try_lock_until `try_lock_until`]]
|
||||
|
||||
[template timed_lock_duration_ref_link[link_text] [link thread.synchronization.mutex_concepts.timed_lockable.timed_lock_duration [link_text]]]
|
||||
[def __timed_lock_duration_ref__ [timed_lock_duration_ref_link `timed_lock()`]]
|
||||
[def __timed_lock_duration [link thread.synchronization.mutex_concepts.timed_lockable.timed_lock_duration `timed_lock`]]
|
||||
|
||||
[template lock_shared_ref_link[link_text] [link thread.synchronization.mutex_concepts.shared_lockable.lock_shared [link_text]]]
|
||||
[def __lock_shared_ref__ [lock_shared_ref_link `lock_shared()`]]
|
||||
[def __lock_shared [link thread.synchronization.mutex_concepts.shared_lockable.lock_shared `lock_shared()`]]
|
||||
|
||||
[template unlock_shared_ref_link[link_text] [link thread.synchronization.mutex_concepts.shared_lockable.unlock_shared [link_text]]]
|
||||
[def __unlock_shared_ref__ [unlock_shared_ref_link `unlock_shared()`]]
|
||||
[def __unlock_shared [link thread.synchronization.mutex_concepts.shared_lockable.unlock_shared `unlock_shared()`]]
|
||||
|
||||
[template try_lock_shared_ref_link[link_text] [link thread.synchronization.mutex_concepts.shared_lockable.try_lock_shared [link_text]]]
|
||||
[def __try_lock_shared_ref__ [try_lock_shared_ref_link `try_lock_shared()`]]
|
||||
[def __try_lock_shared [link thread.synchronization.mutex_concepts.shared_lockable.try_lock_shared `try_lock_shared`]]
|
||||
|
||||
[template timed_lock_shared_ref_link[link_text] [link thread.synchronization.mutex_concepts.shared_lockable.timed_lock_shared [link_text]]]
|
||||
[def __timed_lock_shared_ref__ [timed_lock_shared_ref_link `timed_lock_shared()`]]
|
||||
[def __try_lock_shared_for [link thread.synchronization.mutex_concepts.shared_lockable.try_lock_shared_for `try_lock_shared_for`]]
|
||||
[def __try_lock_shared_for [link thread.synchronization.mutex_concepts.shared_lockable.try_lock_shared_until `try_lock_shared_until`]]
|
||||
|
||||
[template timed_lock_shared_duration_ref_link[link_text] [link thread.synchronization.mutex_concepts.shared_lockable.timed_lock_shared_duration [link_text]]]
|
||||
[def __timed_lock_shared_duration_ref__ [timed_lock_shared_duration_ref_link `timed_lock_shared()`]]
|
||||
[def __try_lock_shared_for [link thread.synchronization.mutex_concepts.shared_lockable.try_lock_shared_for `try_lock_shared_for`]]
|
||||
[def __try_lock_shared_until [link thread.synchronization.mutex_concepts.shared_lockable.try_lock_shared_until `try_lock_shared_until`]]
|
||||
|
||||
[template lock_upgrade_ref_link[link_text] [link thread.synchronization.mutex_concepts.upgrade_lockable.lock_upgrade [link_text]]]
|
||||
[def __lock_upgrade_ref__ [lock_upgrade_ref_link `lock_upgrade()`]]
|
||||
[def __lock_upgrade [link thread.synchronization.mutex_concepts.upgrade_lockable.lock_upgrade `lock_upgrade`]]
|
||||
[def __try_lock_upgrade [link thread.synchronization.mutex_concepts.upgrade_lockable.try_lock_upgrade `try_lock_upgrade`]]
|
||||
[def __try_lock_upgrade_for [link thread.synchronization.mutex_concepts.upgrade_lockable.try_lock_upgrade_for `try_lock_upgrade_for`]]
|
||||
[def __try_lock_upgrade_until [link thread.synchronization.mutex_concepts.upgrade_lockable.try_lock_upgrade_until `try_lock_upgrade_until`]]
|
||||
|
||||
[template unlock_upgrade_ref_link[link_text] [link thread.synchronization.mutex_concepts.upgrade_lockable.unlock_upgrade [link_text]]]
|
||||
[def __unlock_upgrade_ref__ [unlock_upgrade_ref_link `unlock_upgrade()`]]
|
||||
[def __unlock_upgrade [link thread.synchronization.mutex_concepts.upgrade_lockable.unlock_upgrade `unlock_upgrade`]]
|
||||
|
||||
[template unlock_upgrade_and_lock_ref_link[link_text] [link thread.synchronization.mutex_concepts.upgrade_lockable.unlock_upgrade_and_lock [link_text]]]
|
||||
[def __unlock_upgrade_and_lock_ref__ [unlock_upgrade_and_lock_ref_link `unlock_upgrade_and_lock()`]]
|
||||
[def __unlock_upgrade_and_lock [link thread.synchronization.mutex_concepts.upgrade_lockable.unlock_upgrade_and_lock `unlock_upgrade_and_lock`]]
|
||||
|
||||
[template unlock_and_lock_upgrade_ref_link[link_text] [link thread.synchronization.mutex_concepts.upgrade_lockable.unlock_and_lock_upgrade [link_text]]]
|
||||
[def __unlock_and_lock_upgrade_ref__ [unlock_and_lock_upgrade_ref_link `unlock_and_lock_upgrade()`]]
|
||||
[def __unlock_and_lock_upgrade [link thread.synchronization.mutex_concepts.upgrade_lockable.unlock_and_lock_upgrade `unlock_and_lock_upgrade`]]
|
||||
|
||||
[template unlock_upgrade_and_lock_shared_ref_link[link_text] [link thread.synchronization.mutex_concepts.upgrade_lockable.unlock_upgrade_and_lock_shared [link_text]]]
|
||||
[def __unlock_upgrade_and_lock_shared_ref__ [unlock_upgrade_and_lock_shared_ref_link `unlock_upgrade_and_lock_shared()`]]
|
||||
[def __unlock_upgrade_and_lock_shared [link thread.synchronization.mutex_concepts.upgrade_lockable.unlock_upgrade_and_lock_shared `unlock_upgrade_and_lock_shared`]]
|
||||
|
||||
|
||||
[def __try_unlock_shared_and_lock [link thread.synchronization.mutex_concepts.upgrade_lockable.try_unlock_shared_and_lock `try_unlock_shared_and_lock`]]
|
||||
[def __try_unlock_shared_and_lock_for [link thread.synchronization.mutex_concepts.upgrade_lockable.try_unlock_shared_and_lock_for `try_unlock_shared_and_lock_for`]]
|
||||
[def __try_unlock_shared_and_lock_until [link thread.synchronization.mutex_concepts.upgrade_lockable.try_unlock_shared_and_lock_until `try_unlock_shared_and_lock_until`]]
|
||||
|
||||
[def __unlock_and_lock_shared [link thread.synchronization.mutex_concepts.upgrade_lockable.unlock_and_lock_shared `unlock_and_lock_shared`]]
|
||||
|
||||
[def __try_unlock_shared_and_lock_upgrade [link thread.synchronization.mutex_concepts.upgrade_lockable.try_unlock_shared_and_lock_upgrade `try_unlock_shared_and_lock_upgrade`]]
|
||||
[def __try_unlock_shared_and_lock_upgrade_for [link thread.synchronization.mutex_concepts.upgrade_lockable.try_unlock_shared_and_lock_upgrade_for `try_unlock_shared_and_lock_upgrade_for`]]
|
||||
[def __try_unlock_shared_and_lock_upgrade_until [link thread.synchronization.mutex_concepts.upgrade_lockable.try_unlock_shared_and_lock_upgrade_until `try_unlock_shared_and_lock_upgrade_until`]]
|
||||
|
||||
[def __try_unlock_upgrade_and_lock [link thread.synchronization.mutex_concepts.upgrade_lockable.try_unlock_upgrade_and_lock `try_unlock_upgrade_and_lock`]]
|
||||
[def __try_unlock_upgrade_and_lock_for [link thread.synchronization.mutex_concepts.upgrade_lockable.try_unlock_upgrade_and_lock_for `try_unlock_upgrade_and_lock_for`]]
|
||||
[def __try_unlock_upgrade_and_lock_until [link thread.synchronization.mutex_concepts.upgrade_lockable.try_unlock_upgrade_and_lock_until `try_unlock_upgrade_and_lock_until`]]
|
||||
|
||||
|
||||
[template owns_lock_ref_link[link_text] [link thread.synchronization.locks.unique_lock.owns_lock [link_text]]]
|
||||
[def __owns_lock_ref__ [owns_lock_ref_link `owns_lock()`]]
|
||||
[def __owns_lock [owns_lock_ref_link `owns_lock()`]]
|
||||
|
||||
[template owns_lock_shared_ref_link[link_text] [link thread.synchronization.locks.shared_lock.owns_lock [link_text]]]
|
||||
[def __owns_lock_shared_ref__ [owns_lock_shared_ref_link `owns_lock()`]]
|
||||
|
||||
[template mutex_func_ref_link[link_text] [link thread.synchronization.locks.unique_lock.mutex [link_text]]]
|
||||
[def __mutex_func_ref__ [mutex_func_ref_link `mutex()`]]
|
||||
|
||||
[def __boost_thread__ [*Boost.Thread]]
|
||||
[def __not_a_thread__ ['Not-a-Thread]]
|
||||
[def __interruption_points__ [link interruption_points ['interruption points]]]
|
||||
[def __lock_error__ `lock_error`]
|
||||
|
||||
[def __mutex__ [link thread.synchronization.mutex_types.mutex `boost::mutex`]]
|
||||
[def __try_mutex__ [link thread.synchronization.mutex_types.try_mutex `boost::try_mutex`]]
|
||||
[def __timed_mutex__ [link thread.synchronization.mutex_types.timed_mutex `boost::timed_mutex`]]
|
||||
[def __recursive_mutex__ [link thread.synchronization.mutex_types.recursive_mutex `boost::recursive_mutex`]]
|
||||
[def __recursive_try_mutex__ [link thread.synchronization.mutex_types.recursive_try_mutex `boost::recursive_try_mutex`]]
|
||||
[def __recursive_timed_mutex__ [link thread.synchronization.mutex_types.recursive_timed_mutex `boost::recursive_timed_mutex`]]
|
||||
[def __shared_mutex__ [link thread.synchronization.mutex_types.shared_mutex `boost::shared_mutex`]]
|
||||
|
||||
|
||||
[def __StrictLock [link thread.synchronization.lock_concepts.StrictLock `StrictLock`]]
|
||||
|
||||
[template unique_lock_link[link_text] [link thread.synchronization.locks.unique_lock [link_text]]]
|
||||
|
||||
[def __lock_guard__ [link thread.synchronization.lock_guard.lock_guard `boost::lock_guard`]]
|
||||
[def __unique_lock__ [unique_lock_link `boost::unique_lock`]]
|
||||
[def __unique_lock [unique_lock_link `boost::unique_lock`]]
|
||||
[def __shared_lock__ [link thread.synchronization.locks.shared_lock `boost::shared_lock`]]
|
||||
[def __upgrade_lock__ [link thread.synchronization.locks.upgrade_lock `boost::upgrade_lock`]]
|
||||
[def __upgrade_to_unique_lock__ [link thread.synchronization.locks.upgrade_to_unique_lock `boost::upgrade_to_unique_lock`]]
|
||||
[def __reverse_lock [link thread.synchronization.other_locks.reverse_lock `reverse_lock`]]
|
||||
[def __shared_lock_guard [link thread.synchronization.other_locks.shared_lock_guard `shared_lock_guard`]]
|
||||
[def __shared_lock_guard_constructor_adopt [link thread.synchronization.other_locks.shared_lock_guard `shared_lock_guard`]]
|
||||
|
||||
[def __strict_lock [link thread.synchronization.other_locks.strict_locks.strict_lock `strict_lock`]]
|
||||
[def __nested_strict_lock [link thread.synchronization.other_locks.strict_locks.nested_strict_lock `nested_strict_lock`]]
|
||||
|
||||
|
||||
[def __thread__ [link thread.thread_management.thread `boost::thread`]]
|
||||
[def __thread [link thread.thread_management.thread `thread`]]
|
||||
[def __thread_id__ [link thread.thread_management.thread.id `boost::thread::id`]]
|
||||
[template join_link[link_text] [link thread.thread_management.thread.join [link_text]]]
|
||||
[def __join__ [join_link `join()`]]
|
||||
|
||||
[def __try_join_for [link thread.thread_management.thread.try_join_for `try_join_for`]]
|
||||
[def __try_join_until [link thread.thread_management.thread.try_join_until `try_join_until`]]
|
||||
|
||||
[template timed_join_link[link_text] [link thread.thread_management.thread.timed_join [link_text]]]
|
||||
[def __timed_join__ [timed_join_link `timed_join()`]]
|
||||
[def __detach__ [link thread.thread_management.thread.detach `detach()`]]
|
||||
[def __interrupt__ [link thread.thread_management.thread.interrupt `interrupt()`]]
|
||||
[def __sleep__ [link thread.thread_management.this_thread.sleep `boost::this_thread::sleep()`]]
|
||||
[def __sleep_for [link thread.thread_management.this_thread.sleep_for `sleep_for`]]
|
||||
[def __sleep_until [link thread.thread_management.this_thread.sleep_until `sleep_until`]]
|
||||
[def __yield [link thread.thread_management.this_thread.yield `yield`]]
|
||||
[def __get_id [link thread.thread_management.thread.get_id `get_id`]]
|
||||
|
||||
[def __interruption_enabled__ [link thread.thread_management.this_thread.interruption_enabled `boost::this_thread::interruption_enabled()`]]
|
||||
[def __interruption_requested__ [link thread.thread_management.this_thread.interruption_requested `boost::this_thread::interruption_requested()`]]
|
||||
[def __interruption_point__ [link thread.thread_management.this_thread.interruption_point `boost::this_thread::interruption_point()`]]
|
||||
[def __disable_interruption__ [link thread.thread_management.this_thread.disable_interruption `boost::this_thread::disable_interruption`]]
|
||||
[def __restore_interruption__ [link thread.thread_management.this_thread.restore_interruption `boost::this_thread::restore_interruption`]]
|
||||
|
||||
[def __thread_resource_error__ `boost::thread_resource_error`]
|
||||
[def __thread_interrupted__ `boost::thread_interrupted`]
|
||||
[def __barrier__ [link thread.synchronization.barriers.barrier `boost::barrier`]]
|
||||
[def __latch__ [link thread.synchronization.latches.latch `latch`]]
|
||||
|
||||
[template cond_wait_link[link_text] [link thread.synchronization.condvar_ref.condition_variable.wait [link_text]]]
|
||||
[def __cond_wait__ [cond_wait_link `wait()`]]
|
||||
[template cond_timed_wait_link[link_text] [link thread.synchronization.condvar_ref.condition_variable.timed_wait [link_text]]]
|
||||
[def __cond_timed_wait__ [cond_timed_wait_link `timed_wait()`]]
|
||||
|
||||
[def __condition_variable [link thread.synchronization.condvar_ref.condition_variable `condition_variable`]]
|
||||
[def __wait_for [link thread.synchronization.condvar_ref.condition_variable.wait_for `wait_for`]]
|
||||
[def __wait_until [link thread.synchronization.condvar_ref.condition_variable.wait_until `wait_until`]]
|
||||
|
||||
|
||||
[template cond_any_wait_link[link_text] [link thread.synchronization.condvar_ref.condition_variable_any.wait [link_text]]]
|
||||
[def __cond_any_wait__ [cond_any_wait_link `wait()`]]
|
||||
[template cond_any_timed_wait_link[link_text] [link thread.synchronization.condvar_ref.condition_variable_any.timed_wait [link_text]]]
|
||||
[def __cond_any_timed_wait__ [cond_any_timed_wait_link `timed_wait()`]]
|
||||
|
||||
[def __condition_variable_any [link thread.synchronization.condvar_ref.condition_variable_any `condition_variable_any`]]
|
||||
[def __cvany_wait_for [link thread.synchronization.condvar_ref.condition_variable_any.wait_for `wait_for`]]
|
||||
[def __cvany_wait_until [link thread.synchronization.condvar_ref.condition_variable_any.wait_until `wait_until`]]
|
||||
|
||||
[def __blocked__ ['blocked]]
|
||||
|
||||
[include overview.qbk]
|
||||
[include changes.qbk]
|
||||
|
||||
[include thread_ref.qbk]
|
||||
[include scoped_thread.qbk]
|
||||
|
||||
[section:synchronization Synchronization]
|
||||
[include sync_tutorial.qbk]
|
||||
[include mutex_concepts.qbk]
|
||||
[include mutexes.qbk]
|
||||
[include condition_variables.qbk]
|
||||
[include once.qbk]
|
||||
[include barrier.qbk]
|
||||
[include latch.qbk]
|
||||
[include async_executors.qbk]
|
||||
[include futures.qbk]
|
||||
[endsect]
|
||||
|
||||
[include tss.qbk]
|
||||
|
||||
[section:sds Synchronized Data Structures]
|
||||
[include synchronized_value.qbk]
|
||||
[include sync_queues_ref.qbk]
|
||||
[/include sync_streams.qbk]
|
||||
[endsect]
|
||||
|
||||
[include parallel.qbk]
|
||||
|
||||
[include time.qbk]
|
||||
|
||||
[include emulations.qbk]
|
||||
|
||||
[include acknowledgements.qbk]
|
||||
|
||||
[include compliance.qbk]
|
||||
@@ -1,48 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<library name="Thread" dirname="thread" id="thread"
|
||||
last-revision="$Date$"
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<libraryinfo>
|
||||
<author>
|
||||
<firstname>William</firstname>
|
||||
<othername>E.</othername>
|
||||
<surname>Kempf</surname>
|
||||
</author>
|
||||
<copyright>
|
||||
<year>2001</year>
|
||||
<year>2002</year>
|
||||
<year>2003</year>
|
||||
<holder>William E. Kempf</holder>
|
||||
</copyright>
|
||||
<legalnotice>
|
||||
<para>Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)</para>
|
||||
</legalnotice>
|
||||
<librarypurpose>Portable C++ multi-threading</librarypurpose>
|
||||
<librarycategory name="category:concurrent" />
|
||||
<title>Boost.Thread</title>
|
||||
</libraryinfo>
|
||||
<title>Boost.Thread</title>
|
||||
<xi:include href="overview.xml"/>
|
||||
<xi:include href="design.xml"/>
|
||||
<xi:include href="concepts.xml"/>
|
||||
<xi:include href="rationale.xml"/>
|
||||
<xi:include href="reference.xml"/>
|
||||
<xi:include href="faq.xml"/>
|
||||
<xi:include href="configuration.xml"/>
|
||||
<xi:include href="build.xml"/>
|
||||
<xi:include href="implementation_notes.xml"/>
|
||||
<xi:include href="release_notes.xml"/>
|
||||
<xi:include href="glossary.xml"/>
|
||||
<xi:include href="acknowledgements.xml"/>
|
||||
<xi:include href="bibliography.xml"/>
|
||||
</library>
|
||||
1884
doc/thread_ref.qbk
Normal file
1884
doc/thread_ref.qbk
Normal file
File diff suppressed because it is too large
Load Diff
90
doc/time.qbk
Normal file
90
doc/time.qbk
Normal file
@@ -0,0 +1,90 @@
|
||||
[/
|
||||
(C) Copyright 2007-8 Anthony Williams.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:time Time Requirements]
|
||||
|
||||
As of Boost 1.50.0, the __boost_thread__ library uses Boost.Chrono library for all operations that require a
|
||||
time out as defined in the standard c++11. These include (but are not limited to):
|
||||
|
||||
* `boost::this_thread::__sleep_for`
|
||||
* `boost::this_thread::__sleep_until`
|
||||
* `boost::__thread::__try_join_for`
|
||||
* `boost::__thread::__try_join_until`
|
||||
* `boost::__condition_variable::__wait_for`
|
||||
* `boost::__condition_variable::__wait_until`
|
||||
* `boost::__condition_variable_any::__cvany_wait_for`
|
||||
* `boost::__condition_variable_any::__cvany_wait_until`
|
||||
* `__TimedLockable::__try_lock_for`
|
||||
* `__TimedLockable::__try_lock_until`
|
||||
|
||||
[section:deprecated Deprecated]
|
||||
The time related functions introduced in Boost 1.35.0, using the [link date_time Boost.Date_Time] library are deprecated. These include (but are not limited to):
|
||||
|
||||
* __sleep__
|
||||
* __timed_join__
|
||||
* __cond_timed_wait__
|
||||
* __timed_lock_ref__
|
||||
|
||||
For the overloads that accept an absolute time parameter, an object of type [link thread.time.deprecated.system_time `boost::system_time`] is
|
||||
required. Typically, this will be obtained by adding a duration to the current time, obtained with a call to [link
|
||||
thread.time.deprecated.get_system_time `boost::get_system_time()`]. e.g.
|
||||
|
||||
boost::system_time const timeout=boost::get_system_time() + boost::posix_time::milliseconds(500);
|
||||
|
||||
extern bool done;
|
||||
extern boost::mutex m;
|
||||
extern boost::condition_variable cond;
|
||||
|
||||
boost::unique_lock<boost::mutex> lk(m);
|
||||
while(!done)
|
||||
{
|
||||
if(!cond.timed_wait(lk,timeout))
|
||||
{
|
||||
throw "timed out";
|
||||
}
|
||||
}
|
||||
|
||||
For the overloads that accept a ['TimeDuration] parameter, an object of any type that meets the [link
|
||||
date_time.posix_time.time_duration Boost.Date_Time Time Duration requirements] can be used, e.g.
|
||||
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(25));
|
||||
|
||||
boost::mutex m;
|
||||
if(m.timed_lock(boost::posix_time::nanoseconds(100)))
|
||||
{
|
||||
// ...
|
||||
}
|
||||
|
||||
[section:system_time Typedef `system_time`]
|
||||
|
||||
#include <boost/thread/thread_time.hpp>
|
||||
|
||||
typedef boost::posix_time::ptime system_time;
|
||||
|
||||
See the documentation for [link date_time.posix_time.ptime_class `boost::posix_time::ptime`] in the Boost.Date_Time library.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:get_system_time Non-member function `get_system_time()`]
|
||||
|
||||
#include <boost/thread/thread_time.hpp>
|
||||
|
||||
system_time get_system_time();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Returns:] [The current time.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
|
||||
[endsect]
|
||||
206
doc/tss-ref.xml
206
doc/tss-ref.xml
@@ -1,206 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/tss.hpp"
|
||||
last-revision="$Date$">
|
||||
<namespace name="boost">
|
||||
<class name="thread_specific_ptr">
|
||||
<purpose>
|
||||
The <classname>thread_specific_ptr</classname> class defines
|
||||
an interface for using thread specific storage.
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<para>Thread specific storage is data associated with
|
||||
individual threads and is often used to make operations
|
||||
that rely on global data
|
||||
<link linkend="thread.glossary.thread-safe">thread-safe</link>.
|
||||
</para>
|
||||
|
||||
<para>Template <classname>thread_specific_ptr</classname>
|
||||
stores a pointer to an object obtained on a thread-by-thread
|
||||
basis and calls a specified cleanup handler on the contained
|
||||
pointer when the thread terminates. The cleanup handlers are
|
||||
called in the reverse order of construction of the
|
||||
<classname>thread_specific_ptr</classname>s, and for the
|
||||
initial thread are called by the destructor, providing the
|
||||
same ordering guarantees as for normal declarations. Each
|
||||
thread initially stores the null pointer in each
|
||||
<classname>thread_specific_ptr</classname> instance.</para>
|
||||
|
||||
<para>The template <classname>thread_specific_ptr</classname>
|
||||
is useful in the following cases:
|
||||
<itemizedlist>
|
||||
<listitem>An interface was originally written assuming
|
||||
a single thread of control and it is being ported to a
|
||||
multithreaded environment.</listitem>
|
||||
|
||||
<listitem>Each thread of control invokes sequences of
|
||||
methods that share data that are physically unique
|
||||
for each thread, but must be logically accessed
|
||||
through a globally visible access point instead of
|
||||
being explicitly passed.</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
</description>
|
||||
|
||||
<inherit access="private">
|
||||
<type><classname>boost::noncopyable</classname></type>
|
||||
<purpose>Exposition only</purpose>
|
||||
</inherit>
|
||||
|
||||
<constructor>
|
||||
<requires>The expression <code>delete get()</code> is well
|
||||
formed.</requires>
|
||||
|
||||
<effects>A thread-specific data key is allocated and visible to
|
||||
all threads in the process. Upon creation, the value
|
||||
<code>NULL</code> will be associated with the new key in all
|
||||
active threads. A cleanup method is registered with the key
|
||||
that will call <code>delete</code> on the value associated
|
||||
with the key for a thread when it exits. When a thread exits,
|
||||
if a key has a registered cleanup method and the thread has a
|
||||
non-<code>NULL</code> value associated with that key, the value
|
||||
of the key is set to <code>NULL</code> and then the cleanup
|
||||
method is called with the previously associated value as its
|
||||
sole argument. The order in which registered cleanup methods
|
||||
are called when a thread exits is undefined. If after all the
|
||||
cleanup methods have been called for all non-<code>NULL</code>
|
||||
values, there are still some non-<code>NULL</code> values
|
||||
with associated cleanup handlers the result is undefined
|
||||
behavior.</effects>
|
||||
|
||||
<throws><classname>boost::thread_resource_error</classname> if
|
||||
the necessary resources can not be obtained.</throws>
|
||||
|
||||
<notes>There may be an implementation specific limit to the
|
||||
number of thread specific storage objects that can be created,
|
||||
and this limit may be small.</notes>
|
||||
|
||||
<rationale>The most common need for cleanup will be to call
|
||||
<code>delete</code> on the associated value. If other forms
|
||||
of cleanup are required the overloaded constructor should be
|
||||
called instead.</rationale>
|
||||
</constructor>
|
||||
|
||||
<constructor>
|
||||
<parameter name="cleanup">
|
||||
<paramtype>void (*cleanup)(void*)</paramtype>
|
||||
</parameter>
|
||||
|
||||
<effects>A thread-specific data key is allocated and visible to
|
||||
all threads in the process. Upon creation, the value
|
||||
<code>NULL</code> will be associated with the new key in all
|
||||
active threads. The <code>cleanup</code> method is registered
|
||||
with the key and will be called for a thread with the value
|
||||
associated with the key for that thread when it exits. When a
|
||||
thread exits, if a key has a registered cleanup method and the
|
||||
thread has a non-<code>NULL</code> value associated with that
|
||||
key, the value of the key is set to <code>NULL</code> and then
|
||||
the cleanup method is called with the previously associated
|
||||
value as its sole argument. The order in which registered
|
||||
cleanup methods are called when a thread exits is undefined.
|
||||
If after all the cleanup methods have been called for all
|
||||
non-<code>NULL</code> values, there are still some
|
||||
non-<code>NULL</code> values with associated cleanup handlers
|
||||
the result is undefined behavior.</effects>
|
||||
|
||||
<throws><classname>boost::thread_resource_error</classname> if
|
||||
the necessary resources can not be obtained.</throws>
|
||||
|
||||
<notes>There may be an implementation specific limit to the
|
||||
number of thread specific storage objects that can be created,
|
||||
and this limit may be small.</notes>
|
||||
|
||||
<rationale>There is the occasional need to register
|
||||
specialized cleanup methods, or to register no cleanup method
|
||||
at all (done by passing <code>NULL</code> to this constructor.
|
||||
</rationale>
|
||||
</constructor>
|
||||
|
||||
<destructor>
|
||||
<effects>Deletes the thread-specific data key allocated by the
|
||||
constructor. The thread-specific data values associated with
|
||||
the key need not be <code>NULL</code>. It is the responsibility
|
||||
of the application to perform any cleanup actions for data
|
||||
associated with the key.</effects>
|
||||
|
||||
<notes>Does not destroy any data that may be stored in any
|
||||
thread's thread specific storage. For this reason you should
|
||||
not destroy a <classname>thread_specific_ptr</classname> object
|
||||
until you are certain there are no threads running that have
|
||||
made use of its thread specific storage.</notes>
|
||||
|
||||
<rationale>Associated data is not cleaned up because registered
|
||||
cleanup methods need to be run in the thread that allocated the
|
||||
associated data to be guarranteed to work correctly. There's no
|
||||
safe way to inject the call into another thread's execution
|
||||
path, making it impossible to call the cleanup methods safely.
|
||||
</rationale>
|
||||
</destructor>
|
||||
|
||||
<method-group name="modifier functions">
|
||||
<method name="release">
|
||||
<type>T*</type>
|
||||
|
||||
<postconditions><code>*this</code> holds the null pointer
|
||||
for the current thread.</postconditions>
|
||||
|
||||
<returns><code>this->get()</code> prior to the call.</returns>
|
||||
|
||||
<rationale>This method provides a mechanism for the user to
|
||||
relinquish control of the data associated with the
|
||||
thread-specific key.</rationale>
|
||||
</method>
|
||||
|
||||
<method name="reset">
|
||||
<type>void</type>
|
||||
|
||||
<parameter name="p">
|
||||
<paramtype>T*</paramtype>
|
||||
<default>0</default>
|
||||
</parameter>
|
||||
|
||||
<effects>If <code>this->get() != p &&
|
||||
this->get() != NULL</code> then call the
|
||||
associated cleanup function.</effects>
|
||||
|
||||
<postconditions><code>*this</code> holds the pointer
|
||||
<code>p</code> for the current thread.</postconditions>
|
||||
</method>
|
||||
</method-group>
|
||||
|
||||
<method-group name="observer functions">
|
||||
<method name="get" cv="const">
|
||||
<type>T*</type>
|
||||
|
||||
<returns>The object stored in thread specific storage for
|
||||
the current thread for <code>*this</code>.</returns>
|
||||
|
||||
<notes>Each thread initially returns 0.</notes>
|
||||
</method>
|
||||
|
||||
<method name="operator->" cv="const">
|
||||
<type>T*</type>
|
||||
|
||||
<returns><code>this->get()</code>.</returns>
|
||||
</method>
|
||||
|
||||
<method name="operator*()" cv="const">
|
||||
<type>T&</type>
|
||||
|
||||
<requires><code>this->get() != 0</code></requires>
|
||||
|
||||
<returns><code>this->get()</code>.</returns>
|
||||
</method>
|
||||
</method-group>
|
||||
</class>
|
||||
</namespace>
|
||||
</header>
|
||||
200
doc/tss.qbk
Normal file
200
doc/tss.qbk
Normal file
@@ -0,0 +1,200 @@
|
||||
[/
|
||||
(C) Copyright 2007-8 Anthony Williams.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section Thread Local Storage]
|
||||
|
||||
[heading Synopsis]
|
||||
|
||||
Thread local storage allows multi-threaded applications to have a separate instance of a given data item for each thread. Where a
|
||||
single-threaded application would use static or global data, this could lead to contention, deadlock or data corruption in a
|
||||
multi-threaded application. One example is the C `errno` variable, used for storing the error code related to functions from the
|
||||
Standard C library. It is common practice (and required by POSIX) for compilers that support multi-threaded applications to provide
|
||||
a separate instance of `errno` for each thread, in order to avoid different threads competing to read or update the value.
|
||||
|
||||
Though compilers often provide this facility in the form of extensions to the declaration syntax (such as `__declspec(thread)` or
|
||||
`__thread` annotations on `static` or namespace-scope variable declarations), such support is non-portable, and is often limited in
|
||||
some way, such as only supporting POD types.
|
||||
|
||||
[heading Portable thread-local storage with `boost::thread_specific_ptr`]
|
||||
|
||||
`boost::thread_specific_ptr` provides a portable mechanism for thread-local storage that works on all compilers supported by
|
||||
__boost_thread__. Each instance of `boost::thread_specific_ptr` represents a pointer to an object (such as `errno`) where each
|
||||
thread must have a distinct value. The value for the current thread can be obtained using the `get()` member function, or by using
|
||||
the `*` and `->` pointer deference operators. Initially the pointer has a value of `NULL` in each thread, but the value for the
|
||||
current thread can be set using the `reset()` member function.
|
||||
|
||||
If the value of the pointer for the current thread is changed using `reset()`, then the previous value is destroyed by calling the
|
||||
cleanup routine. Alternatively, the stored value can be reset to `NULL` and the prior value returned by calling the `release()`
|
||||
member function, allowing the application to take back responsibility for destroying the object.
|
||||
|
||||
[heading Cleanup at thread exit]
|
||||
|
||||
When a thread exits, the objects associated with each `boost::thread_specific_ptr` instance are destroyed. By default, the object
|
||||
pointed to by a pointer `p` is destroyed by invoking `delete p`, but this can be overridden for a specific instance of
|
||||
`boost::thread_specific_ptr` by providing a cleanup routine to the constructor. In this case, the object is destroyed by invoking
|
||||
`func(p)` where `func` is the cleanup routine supplied to the constructor. The cleanup functions are called in an unspecified
|
||||
order. If a cleanup routine sets the value of associated with an instance of `boost::thread_specific_ptr` that has already been
|
||||
cleaned up, that value is added to the cleanup list. Cleanup finishes when there are no outstanding instances of
|
||||
`boost::thread_specific_ptr` with values.
|
||||
|
||||
Note: on some platforms, cleanup of thread-specific data is not
|
||||
performed for threads created with the platform's native API. On those
|
||||
platforms such cleanup is only done for threads that are started with
|
||||
`boost::thread` unless `boost::on_thread_exit()` is called manually
|
||||
from that thread.
|
||||
|
||||
[heading Rationale about the nature of the key]
|
||||
|
||||
Boost.Thread uses the address of the `thread_specific_ptr` instance as key of the thread specific pointers. This avoids to create/destroy a key which will need a lock to protect from race conditions. This has a little performance liability, as the access must be done using an associative container.
|
||||
|
||||
[section:thread_specific_ptr Class `thread_specific_ptr`]
|
||||
|
||||
// #include <boost/thread/tss.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template <typename T>
|
||||
class thread_specific_ptr
|
||||
{
|
||||
public:
|
||||
thread_specific_ptr();
|
||||
explicit thread_specific_ptr(void (*cleanup_function)(T*));
|
||||
~thread_specific_ptr();
|
||||
|
||||
T* get() const;
|
||||
T* operator->() const;
|
||||
T& operator*() const;
|
||||
|
||||
T* release();
|
||||
void reset(T* new_value=0);
|
||||
};
|
||||
}
|
||||
|
||||
[section:default_constructor `thread_specific_ptr();`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`delete this->get()` is well-formed.]]
|
||||
|
||||
[[Effects:] [Construct a `thread_specific_ptr` object for storing a pointer to an object of type `T` specific to each thread. The
|
||||
default `delete`-based cleanup function will be used to destroy any thread-local objects when `reset()` is called, or the thread
|
||||
exits.]]
|
||||
|
||||
[[Throws:] [`boost::thread_resource_error` if an error occurs.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:constructor_with_custom_cleanup `explicit thread_specific_ptr(void (*cleanup_function)(T*));`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`cleanup_function(this->get())` does not throw any exceptions.]]
|
||||
|
||||
[[Effects:] [Construct a `thread_specific_ptr` object for storing a pointer to an object of type `T` specific to each thread. The
|
||||
supplied `cleanup_function` will be used to destroy any thread-local objects when `reset()` is called, or the thread exits.]]
|
||||
|
||||
[[Throws:] [`boost::thread_resource_error` if an error occurs.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:destructor `~thread_specific_ptr();`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [All the thread specific instances associated to this thread_specific_ptr (except maybe the one associated to this thread) must be null.]]
|
||||
|
||||
[[Effects:] [Calls `this->reset()` to clean up the associated value for the current thread, and destroys `*this`.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
[[Remarks:] [The requirement is due to the fact that in order to delete all these instances, the implementation should be forced to maintain a list of all the threads having an associated specific ptr, which is against the goal of thread specific data.]]
|
||||
|
||||
]
|
||||
|
||||
[note Care needs to be taken to ensure that any threads still running after an instance of `boost::thread_specific_ptr` has been
|
||||
destroyed do not call any member functions on that instance.]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:get `T* get() const;`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Returns:] [The pointer associated with the current thread.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[note The initial value associated with an instance of `boost::thread_specific_ptr` is `NULL` for each thread.]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:operator_arrow `T* operator->() const;`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Returns:] [`this->get()`]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:operator_star `T& operator*() const;`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`this->get` is not `NULL`.]]
|
||||
|
||||
[[Returns:] [`*(this->get())`]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:reset `void reset(T* new_value=0);`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If `this->get()!=new_value` and `this->get()` is non-`NULL`, invoke `delete this->get()` or
|
||||
`cleanup_function(this->get())` as appropriate. Store `new_value` as the pointer associated with the current thread.]]
|
||||
|
||||
[[Postcondition:] [`this->get()==new_value`]]
|
||||
|
||||
[[Throws:] [`boost::thread_resource_error` if an error occurs.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:release `T* release();`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Return `this->get()` and store `NULL` as the pointer associated with the current thread without invoking the cleanup
|
||||
function.]]
|
||||
|
||||
[[Postcondition:] [`this->get()==0`]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
@@ -1,82 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
|
||||
<!ENTITY % thread.entities SYSTEM "entities.xml">
|
||||
%thread.entities;
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/xtime.hpp"
|
||||
last-revision="$Date$">
|
||||
<namespace name="boost">
|
||||
<enum name="xtime_clock_types">
|
||||
<enumvalue name="TIME_UTC" />
|
||||
|
||||
<purpose>
|
||||
<para>Specifies the clock type to use when creating
|
||||
an object of type <classname>xtime</classname>.</para>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<para>The only clock type supported by &Boost.Thread; is
|
||||
<code>TIME_UTC</code>. The epoch for <code>TIME_UTC</code>
|
||||
is 1970-01-01 00:00:00.</para>
|
||||
</description>
|
||||
</enum>
|
||||
|
||||
<struct name="xtime">
|
||||
<purpose>
|
||||
<simpara>An object of type <classname>xtime</classname>
|
||||
defines a time that is used to perform high-resolution time operations.
|
||||
This is a temporary solution that will be replaced by a more robust time
|
||||
library once available in Boost.</simpara>
|
||||
</purpose>
|
||||
|
||||
<description>
|
||||
<simpara>The <classname>xtime</classname> type is used to represent a point on
|
||||
some time scale or a duration in time. This type may be proposed for the C standard by
|
||||
Markus Kuhn. &Boost.Thread; provides only a very minimal implementation of this
|
||||
proposal; it is expected that a full implementation (or some other time
|
||||
library) will be provided in Boost as a separate library, at which time &Boost.Thread;
|
||||
will deprecate its own implementation.</simpara>
|
||||
|
||||
<simpara><emphasis role="bold">Note</emphasis> that the resolution is
|
||||
implementation specific. For many implementations the best resolution
|
||||
of time is far more than one nanosecond, and even when the resolution
|
||||
is reasonably good, the latency of a call to <code>xtime_get()</code>
|
||||
may be significant. For maximum portability, avoid durations of less than
|
||||
one second.</simpara>
|
||||
</description>
|
||||
|
||||
<free-function-group name="creation">
|
||||
<function name="xtime_get">
|
||||
<type>int</type>
|
||||
|
||||
<parameter name="xtp">
|
||||
<paramtype><classname>xtime</classname>*</paramtype>
|
||||
</parameter>
|
||||
|
||||
<parameter name="clock_type">
|
||||
<paramtype>int</paramtype>
|
||||
</parameter>
|
||||
|
||||
<postconditions>
|
||||
<simpara><code>xtp</code> represents the current point in
|
||||
time as a duration since the epoch specified by
|
||||
<code>clock_type</code>.</simpara>
|
||||
</postconditions>
|
||||
|
||||
<returns>
|
||||
<simpara><code>clock_type</code> if successful, otherwise 0.</simpara>
|
||||
</returns>
|
||||
</function>
|
||||
</free-function-group>
|
||||
|
||||
<data-member name="sec">
|
||||
<type><emphasis>platform-specific-type</emphasis></type>
|
||||
</data-member>
|
||||
</struct>
|
||||
</namespace>
|
||||
</header>
|
||||
@@ -1,2 +0,0 @@
|
||||
bin
|
||||
*.pdb
|
||||
116
example/ba_externallly_locked.cpp
Normal file
116
example/ba_externallly_locked.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
// Copyright (C) 2012 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/lockable_adapter.hpp>
|
||||
#include <boost/thread/externally_locked.hpp>
|
||||
#include <boost/thread/strict_lock.hpp>
|
||||
#include <boost/thread/lock_types.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace boost;
|
||||
|
||||
class BankAccount
|
||||
{
|
||||
int balance_;
|
||||
public:
|
||||
void Deposit(int amount)
|
||||
{
|
||||
balance_ += amount;
|
||||
}
|
||||
void Withdraw(int amount)
|
||||
{
|
||||
balance_ -= amount;
|
||||
}
|
||||
int GetBalance()
|
||||
{
|
||||
return balance_;
|
||||
}
|
||||
};
|
||||
|
||||
//[AccountManager
|
||||
class AccountManager: public basic_lockable_adapter<mutex>
|
||||
{
|
||||
public:
|
||||
typedef basic_lockable_adapter<mutex> lockable_base_type;
|
||||
AccountManager() :
|
||||
lockable_base_type(), checkingAcct_(*this), savingsAcct_(*this)
|
||||
{
|
||||
}
|
||||
inline void Checking2Savings(int amount);
|
||||
inline void AMoreComplicatedChecking2Savings(int amount);
|
||||
private:
|
||||
/*<-*/
|
||||
bool some_condition()
|
||||
{
|
||||
return true;
|
||||
} /*->*/
|
||||
externally_locked<BankAccount, AccountManager > checkingAcct_;
|
||||
externally_locked<BankAccount, AccountManager > savingsAcct_;
|
||||
};
|
||||
//]
|
||||
|
||||
//[Checking2Savings
|
||||
void AccountManager::Checking2Savings(int amount)
|
||||
{
|
||||
strict_lock<AccountManager> guard(*this);
|
||||
checkingAcct_.get(guard).Withdraw(amount);
|
||||
savingsAcct_.get(guard).Deposit(amount);
|
||||
}
|
||||
//]
|
||||
|
||||
//#if DO_NOT_COMPILE
|
||||
////[AMoreComplicatedChecking2Savings_DO_NOT_COMPILE
|
||||
//void AccountManager::AMoreComplicatedChecking2Savings(int amount) {
|
||||
// unique_lock<AccountManager> guard(*this);
|
||||
// if (some_condition()) {
|
||||
// guard.lock();
|
||||
// }
|
||||
// checkingAcct_.get(guard).Withdraw(amount);
|
||||
// savingsAcct_.get(guard).Deposit(amount);
|
||||
// guard1.unlock();
|
||||
//}
|
||||
////]
|
||||
//#elif DO_NOT_COMPILE_2
|
||||
////[AMoreComplicatedChecking2Savings_DO_NOT_COMPILE2
|
||||
//void AccountManager::AMoreComplicatedChecking2Savings(int amount) {
|
||||
// unique_lock<AccountManager> guard1(*this);
|
||||
// if (some_condition()) {
|
||||
// guard1.lock();
|
||||
// }
|
||||
// {
|
||||
// strict_lock<AccountManager> guard(guard1);
|
||||
// checkingAcct_.get(guard).Withdraw(amount);
|
||||
// savingsAcct_.get(guard).Deposit(amount);
|
||||
// }
|
||||
// guard1.unlock();
|
||||
//}
|
||||
////]
|
||||
//#else
|
||||
////[AMoreComplicatedChecking2Savings
|
||||
void AccountManager::AMoreComplicatedChecking2Savings(int amount) {
|
||||
unique_lock<AccountManager> guard1(*this);
|
||||
if (some_condition()) {
|
||||
guard1.lock();
|
||||
}
|
||||
{
|
||||
nested_strict_lock<unique_lock<AccountManager> > guard(guard1);
|
||||
checkingAcct_.get(guard).Withdraw(amount);
|
||||
savingsAcct_.get(guard).Deposit(amount);
|
||||
}
|
||||
guard1.unlock();
|
||||
}
|
||||
////]
|
||||
//#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
AccountManager mgr;
|
||||
mgr.Checking2Savings(100);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/thread/condition.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include "../test/remove_error_code_unused_warning.hpp"
|
||||
|
||||
class bounded_buffer : private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
typedef boost::mutex::scoped_lock lock;
|
||||
typedef boost::unique_lock<boost::mutex> lock;
|
||||
|
||||
bounded_buffer(int n) : begin(0), end(0), buffered(0), circular_buf(n) { }
|
||||
bounded_buffer(int n) : boost::noncopyable(), begin(0), end(0), buffered(0), circular_buf(n) { }
|
||||
|
||||
void send (int m) {
|
||||
lock lk(monitor);
|
||||
@@ -38,19 +39,26 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
int begin, end, buffered;
|
||||
int begin, end;
|
||||
std::vector<int>::size_type buffered;
|
||||
std::vector<int> circular_buf;
|
||||
boost::condition buffer_not_full, buffer_not_empty;
|
||||
boost::condition_variable_any buffer_not_full, buffer_not_empty;
|
||||
boost::mutex monitor;
|
||||
};
|
||||
|
||||
bounded_buffer buf(2);
|
||||
|
||||
boost::mutex io_mutex;
|
||||
|
||||
void sender() {
|
||||
int n = 0;
|
||||
while (n < 100) {
|
||||
while (n < 1000000) {
|
||||
buf.send(n);
|
||||
std::cout << "sent: " << n << std::endl;
|
||||
if(!(n%10000))
|
||||
{
|
||||
boost::unique_lock<boost::mutex> io_lock(io_mutex);
|
||||
std::cout << "sent: " << n << std::endl;
|
||||
}
|
||||
++n;
|
||||
}
|
||||
buf.send(-1);
|
||||
@@ -60,15 +68,24 @@ void receiver() {
|
||||
int n;
|
||||
do {
|
||||
n = buf.receive();
|
||||
std::cout << "received: " << n << std::endl;
|
||||
if(!(n%10000))
|
||||
{
|
||||
boost::unique_lock<boost::mutex> io_lock(io_mutex);
|
||||
std::cout << "received: " << n << std::endl;
|
||||
}
|
||||
} while (n != -1); // -1 indicates end of buffer
|
||||
buf.send(-1);
|
||||
}
|
||||
|
||||
int main(int, char*[])
|
||||
{
|
||||
boost::thread thrd1(&sender);
|
||||
boost::thread thrd2(&receiver);
|
||||
boost::thread thrd3(&receiver);
|
||||
boost::thread thrd4(&receiver);
|
||||
thrd1.join();
|
||||
thrd2.join();
|
||||
thrd3.join();
|
||||
thrd4.join();
|
||||
return 0;
|
||||
}
|
||||
|
||||
150
example/executor.cpp
Normal file
150
example/executor.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
// Copyright (C) 2012-2013 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
#define BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
//#define BOOST_THREAD_USES_LOG
|
||||
#define BOOST_THREAD_USES_LOG_THREAD_ID
|
||||
#define BOOST_THREAD_QUEUE_DEPRECATE_OLD
|
||||
|
||||
#include <boost/thread/caller_context.hpp>
|
||||
#include <boost/thread/executors/basic_thread_pool.hpp>
|
||||
#include <boost/thread/executors/loop_executor.hpp>
|
||||
#include <boost/thread/executors/serial_executor.hpp>
|
||||
#include <boost/thread/executors/inline_executor.hpp>
|
||||
#include <boost/thread/executors/thread_executor.hpp>
|
||||
#include <boost/thread/executors/executor.hpp>
|
||||
#include <boost/thread/executors/executor_adaptor.hpp>
|
||||
#include <boost/thread/executor.hpp>
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
void p1()
|
||||
{
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
//boost::this_thread::sleep_for(boost::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
void p2()
|
||||
{
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
//boost::this_thread::sleep_for(boost::chrono::seconds(10));
|
||||
}
|
||||
|
||||
int f1()
|
||||
{
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
boost::this_thread::sleep_for(boost::chrono::seconds(1));
|
||||
return 1;
|
||||
}
|
||||
int f2(int i)
|
||||
{
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
boost::this_thread::sleep_for(boost::chrono::seconds(2));
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
void submit_some(boost::executor& tp)
|
||||
{
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
tp.submit(&p2);
|
||||
}
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
tp.submit(&p1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void at_th_entry(boost::basic_thread_pool& )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int test_executor_adaptor()
|
||||
{
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
boost::executor_adaptor < boost::basic_thread_pool > ea(4);
|
||||
submit_some( ea);
|
||||
{
|
||||
boost::future<int> t1 = boost::async(ea, &f1);
|
||||
boost::future<int> t2 = boost::async(ea, &f1);
|
||||
// std::cout << BOOST_CONTEXTOF << " t1= " << t1.get() << std::endl;
|
||||
// std::cout << BOOST_CONTEXTOF << " t2= " << t2.get() << std::endl;
|
||||
}
|
||||
submit_some(ea);
|
||||
{
|
||||
boost::basic_thread_pool ea3(1);
|
||||
boost::future<int> t1 = boost::async(ea3, &f1);
|
||||
boost::future<int> t2 = boost::async(ea3, &f1);
|
||||
//boost::future<int> t2 = boost::async(ea3, f2, 1); // todo this doesn't compiles yet on C++11
|
||||
//boost::future<int> t2 = boost::async(ea3, boost::bind(f2, 1)); // todo this doesn't compiles yet on C++98
|
||||
// std::cout << BOOST_CONTEXTOF << " t1= " << t1.get() << std::endl;
|
||||
// std::cout << BOOST_CONTEXTOF << " t2= " << t2.get() << std::endl;
|
||||
}
|
||||
submit_some(ea);
|
||||
}
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
{
|
||||
boost::executor_adaptor < boost::loop_executor > ea2;
|
||||
submit_some( ea2);
|
||||
ea2.underlying_executor().run_queued_closures();
|
||||
}
|
||||
#if ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
{
|
||||
boost::executor_adaptor < boost::basic_thread_pool > ea1(4);
|
||||
boost::executor_adaptor < boost::serial_executor > ea2(ea1);
|
||||
submit_some(ea2);
|
||||
}
|
||||
#endif
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
{
|
||||
boost::executor_adaptor < boost::inline_executor > ea1;
|
||||
submit_some(ea1);
|
||||
}
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
{
|
||||
boost::executor_adaptor < boost::thread_executor > ea1;
|
||||
submit_some(ea1);
|
||||
}
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
{
|
||||
boost::basic_thread_pool ea(4, at_th_entry);
|
||||
boost::future<int> t1 = boost::async(ea, &f1);
|
||||
// std::cout << BOOST_CONTEXTOF << " t1= " << t1.get() << std::endl;
|
||||
}
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
std::cout << "ERROR= " << ex.what() << "" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << " ERROR= exception thrown" << std::endl;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
return test_executor_adaptor();
|
||||
}
|
||||
91
example/fib_task_region.cpp
Normal file
91
example/fib_task_region.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
// Copyright (C) 2012 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
#define BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
|
||||
#include <boost/thread/experimental/task_region.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#if ! defined BOOST_NO_CXX11_RANGE_BASED_FOR && ! defined BOOST_NO_CXX11_LAMBDAS
|
||||
|
||||
int fib_task_region(int n)
|
||||
{
|
||||
using boost::experimental::parallel::task_region;
|
||||
using boost::experimental::parallel::task_region_handle;
|
||||
|
||||
if (n == 0) return 0;
|
||||
if (n == 1) return 1;
|
||||
|
||||
int n1;
|
||||
int n2;
|
||||
|
||||
task_region([&](task_region_handle& trh)
|
||||
{
|
||||
trh.run([&]
|
||||
{
|
||||
n1 = fib_task_region(n - 1);
|
||||
});
|
||||
|
||||
n2 = fib_task_region(n - 2);
|
||||
});
|
||||
|
||||
return n1 + n2;
|
||||
}
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
template <class Ex>
|
||||
int fib_task_region_gen( Ex& ex, int n)
|
||||
{
|
||||
using boost::experimental::parallel::task_region;
|
||||
using boost::experimental::parallel::task_region_handle_gen;
|
||||
|
||||
if (n == 0) return 0;
|
||||
if (n == 1) return 1;
|
||||
|
||||
int n1;
|
||||
int n2;
|
||||
|
||||
task_region(ex, [&](task_region_handle_gen<Ex>& trh)
|
||||
{
|
||||
trh.run([&]
|
||||
{
|
||||
n1 = fib_task_region(n - 1);
|
||||
});
|
||||
|
||||
n2 = fib_task_region(n - 2);
|
||||
});
|
||||
|
||||
return n1 + n2;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
for (int i = 0; i<10; ++i) {
|
||||
std::cout << fib_task_region(i) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
boost::basic_thread_pool tp;
|
||||
for (int i = 0; i<10; ++i) {
|
||||
std::cout << fib_task_region_gen(tp,i) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
103
example/future_fallback_to.cpp
Normal file
103
example/future_fallback_to.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
// Copyright (C) 2012-2013 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
//#define BOOST_THREAD_USES_LOG
|
||||
#define BOOST_THREAD_USES_LOG_THREAD_ID
|
||||
|
||||
#include <boost/thread/detail/log.hpp>
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
|
||||
|
||||
int p1_ex()
|
||||
{
|
||||
BOOST_THREAD_LOG << "P1" << BOOST_THREAD_END_LOG;
|
||||
throw std::logic_error("kk");
|
||||
}
|
||||
|
||||
int p1()
|
||||
{
|
||||
BOOST_THREAD_LOG << "P1" << BOOST_THREAD_END_LOG;
|
||||
return 1;;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const int number_of_tests = 100;
|
||||
BOOST_THREAD_LOG << "<MAIN" << BOOST_THREAD_END_LOG;
|
||||
{
|
||||
for (int i=0; i< number_of_tests; i++)
|
||||
try
|
||||
{
|
||||
//boost::future<int> f1 = boost::async(boost::launch::async, &p1);
|
||||
BOOST_THREAD_LOG << "" << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::async(&p1);
|
||||
BOOST_THREAD_LOG << "" << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f2 = f1.fallback_to(-1);
|
||||
BOOST_THREAD_LOG << "" << BOOST_THREAD_END_LOG;
|
||||
f2.wait();
|
||||
BOOST_ASSERT(f2.get()==1);
|
||||
BOOST_THREAD_LOG << "" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
std::cout << "ERRORRRRR "<<ex.what() << "" << std::endl;
|
||||
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << " ERRORRRRR exception thrown" << std::endl;
|
||||
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
for (int i=0; i< number_of_tests; i++)
|
||||
try
|
||||
{
|
||||
BOOST_THREAD_LOG << "" << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, &p1_ex);
|
||||
BOOST_THREAD_LOG << "" << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f2 = f1.fallback_to(-1);
|
||||
BOOST_THREAD_LOG << "" << BOOST_THREAD_END_LOG;
|
||||
f2.wait();
|
||||
BOOST_ASSERT(f2.get()==-1);
|
||||
BOOST_THREAD_LOG << "" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
std::cout << "ERRORRRRR "<<ex.what() << "" << std::endl;
|
||||
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << " ERRORRRRR exception thrown" << std::endl;
|
||||
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
BOOST_THREAD_LOG << "MAIN>" << BOOST_THREAD_END_LOG;
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
132
example/future_then.cpp
Normal file
132
example/future_then.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
// Copyright (C) 2012-2013 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
//#define BOOST_THREAD_USES_LOG
|
||||
#define BOOST_THREAD_USES_LOG_THREAD_ID
|
||||
|
||||
#include <boost/thread/detail/log.hpp>
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <string>
|
||||
#if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
|
||||
|
||||
int p1()
|
||||
{
|
||||
BOOST_THREAD_LOG << "P1" << BOOST_THREAD_END_LOG;
|
||||
return 123;
|
||||
}
|
||||
|
||||
int p2(boost::future<int> f)
|
||||
{
|
||||
BOOST_THREAD_LOG << "P2<" << BOOST_THREAD_END_LOG;
|
||||
try
|
||||
{
|
||||
return 2 * f.get();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
std::cout << "ERRORRRRR "<<ex.what() << "" << std::endl;
|
||||
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
BOOST_THREAD_LOG << "P2>" << BOOST_THREAD_END_LOG;
|
||||
return 0;
|
||||
}
|
||||
int p2s(boost::shared_future<int> f)
|
||||
{
|
||||
BOOST_THREAD_LOG << "<P2S" << BOOST_THREAD_END_LOG;
|
||||
try
|
||||
{
|
||||
return 2 * f.get();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
std::cout << "ERRORRRRR "<<ex.what() << "" << std::endl;
|
||||
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
BOOST_THREAD_LOG << "P2S>" << BOOST_THREAD_END_LOG;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const int number_of_tests = 100;
|
||||
BOOST_THREAD_LOG << "<MAIN" << BOOST_THREAD_END_LOG;
|
||||
{
|
||||
for (int i=0; i< number_of_tests; i++)
|
||||
try
|
||||
{
|
||||
BOOST_THREAD_LOG << "" << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::async(&p1);
|
||||
BOOST_THREAD_LOG << "" << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f2 = f1.then(&p2);
|
||||
BOOST_THREAD_LOG << "" << BOOST_THREAD_END_LOG;
|
||||
(void)f2.get();
|
||||
BOOST_THREAD_LOG << "" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
std::cout << "ERRORRRRR "<<ex.what() << "" << std::endl;
|
||||
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
{
|
||||
for (int i=0; i< number_of_tests; i++)
|
||||
try
|
||||
{
|
||||
BOOST_THREAD_LOG << "" << BOOST_THREAD_END_LOG;
|
||||
boost::shared_future<int> f1 = boost::async(&p1).share();
|
||||
BOOST_THREAD_LOG << "" << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f2 = f1.then(&p2s);
|
||||
BOOST_THREAD_LOG << "" << BOOST_THREAD_END_LOG;
|
||||
(void)f2.get();
|
||||
BOOST_THREAD_LOG << "" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
std::cout << "ERRORRRRR "<<ex.what() << "" << std::endl;
|
||||
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
BOOST_THREAD_LOG << "MAIN>" << BOOST_THREAD_END_LOG;
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
70
example/future_unwrap.cpp
Normal file
70
example/future_unwrap.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
// Copyright (C) 2012-2013 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
//#define BOOST_THREAD_USES_LOG
|
||||
#define BOOST_THREAD_USES_LOG_THREAD_ID
|
||||
|
||||
#include <boost/thread/detail/log.hpp>
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_FUTURE_UNWRAP
|
||||
|
||||
int p1()
|
||||
{
|
||||
BOOST_THREAD_LOG << "P1" << BOOST_THREAD_END_LOG;
|
||||
return 123;
|
||||
}
|
||||
|
||||
boost::future<int> p2()
|
||||
{
|
||||
BOOST_THREAD_LOG << "<P2" << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
|
||||
BOOST_THREAD_LOG << "P2>" << BOOST_THREAD_END_LOG;
|
||||
return boost::move(f1);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const int number_of_tests = 100;
|
||||
BOOST_THREAD_LOG << "<MAIN" << BOOST_THREAD_END_LOG;
|
||||
for (int i=0; i< number_of_tests; i++)
|
||||
try
|
||||
{
|
||||
boost::future<boost::future<int> > outer_future = boost::async(boost::launch::async, &p2);
|
||||
boost::future<int> inner_future = outer_future.unwrap();
|
||||
int ii = inner_future.get();
|
||||
BOOST_THREAD_LOG << "ii= "<< ii << "" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
std::cout << "ERRORRRRR "<<ex.what() << "" << std::endl;
|
||||
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << " ERRORRRRR exception thrown" << std::endl;
|
||||
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
return 2;
|
||||
}
|
||||
BOOST_THREAD_LOG << "MAIN>" << BOOST_THREAD_END_LOG;
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
323
example/future_when_all.cpp
Normal file
323
example/future_when_all.cpp
Normal file
@@ -0,0 +1,323 @@
|
||||
// Copyright (C) 2012-2013 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
//#define BOOST_THREAD_USES_LOG
|
||||
#define BOOST_THREAD_USES_LOG_THREAD_ID
|
||||
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/thread/csbl/vector.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/thread/detail/log.hpp>
|
||||
#include <string>
|
||||
#if defined BOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY
|
||||
|
||||
int p1()
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< "P1" << BOOST_THREAD_END_LOG;
|
||||
boost::this_thread::sleep_for(boost::chrono::seconds(1));
|
||||
return 123;
|
||||
}
|
||||
int p1b()
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< "P1b" << BOOST_THREAD_END_LOG;
|
||||
boost::this_thread::sleep_for(boost::chrono::seconds(1));
|
||||
return 321;
|
||||
}
|
||||
|
||||
int p2(boost::future<int> f)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< " P2 " << BOOST_THREAD_END_LOG;
|
||||
try
|
||||
{
|
||||
return 2 * f.get();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< "ERRORRRRR " << ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
BOOST_THREAD_LOG
|
||||
<< "P2>" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
int p2s(boost::shared_future<int> f)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< "<P2" << BOOST_THREAD_END_LOG;
|
||||
try
|
||||
{
|
||||
return 2 * f.get();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< "ERRORRRRR " << ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
BOOST_THREAD_LOG
|
||||
<< "P2>" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< "<MAIN" << BOOST_THREAD_END_LOG;
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<boost::csbl::tuple<> > all0 = boost::when_all();
|
||||
BOOST_THREAD_LOG
|
||||
<< BOOST_THREAD_END_LOG;
|
||||
}
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
|
||||
boost::future<boost::csbl::tuple<boost::future<int> > > all = boost::when_all(boost::move(f1));
|
||||
boost::csbl::tuple<boost::future<int> > res = all.get();
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::async(boost::launch::deferred, &p1);
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<boost::csbl::tuple<boost::future<int> > > all = boost::when_all(boost::move(f1));
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::csbl::tuple<boost::future<int> > res = all.get();
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
#endif
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::make_ready_future(1);
|
||||
boost::future<boost::csbl::tuple<boost::future<int> > > all = boost::when_all(boost::move(f1));
|
||||
boost::csbl::tuple<boost::future<int> > res = all.get();
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
|
||||
boost::future<int> f2 = boost::async(boost::launch::async, &p1b);
|
||||
boost::future<boost::csbl::tuple<boost::future<int>,boost::future<int> > > all = boost::when_all(boost::move(f1), boost::move(f2));
|
||||
//(void) all.wait();
|
||||
boost::csbl::tuple<boost::future<int>,boost::future<int> > res = all.get();
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<1>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
|
||||
boost::future<std::string> f2 = boost::make_ready_future(std::string("nnnnnnn"));;
|
||||
boost::future<boost::csbl::tuple<boost::future<int>, boost::future<std::string> > > all = boost::when_all(boost::move(f1), boost::move(f2));
|
||||
//(void) all.wait();
|
||||
boost::csbl::tuple<boost::future<int>, boost::future<std::string> > res = all.get();
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<1>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::csbl::vector<boost::future<int> > v;
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
v.push_back(boost::async(boost::launch::async, &p1));
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
v.push_back(boost::async(boost::launch::async, &p1b));
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<boost::csbl::vector<boost::future<int> > > all = boost::when_all(v.begin(), v.end());
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::csbl::vector<boost::future<int> > res = all.get();
|
||||
BOOST_THREAD_LOG
|
||||
<< res[0].get() <<" " << BOOST_THREAD_END_LOG;
|
||||
BOOST_THREAD_LOG
|
||||
<< res[1].get() <<" " << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< "ERRORRRRR " << ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<boost::csbl::tuple<> > all0 = boost::when_any();
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
|
||||
boost::future<boost::csbl::tuple<boost::future<int> > > all = boost::when_any(boost::move(f1));
|
||||
boost::csbl::tuple<boost::future<int> > res = all.get();
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::async(boost::launch::deferred, &p1);
|
||||
boost::future<boost::csbl::tuple<boost::future<int> > > all = boost::when_any(boost::move(f1));
|
||||
boost::csbl::tuple<boost::future<int> > res = all.get();
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
#endif
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
|
||||
boost::future<int> f2 = boost::async(boost::launch::async, &p1b);
|
||||
boost::future<boost::csbl::tuple<boost::future<int>,boost::future<int> > > all = boost::when_any(boost::move(f1), boost::move(f2));
|
||||
boost::csbl::tuple<boost::future<int>,boost::future<int> > res = all.get();
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<1>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::make_ready_future(1);
|
||||
boost::future<int> f2 = boost::async(boost::launch::async, &p1b);
|
||||
boost::future<boost::csbl::tuple<boost::future<int>,boost::future<int> > > all = boost::when_any(boost::move(f1), boost::move(f2));
|
||||
boost::csbl::tuple<boost::future<int>,boost::future<int> > res = all.get();
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<1>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<std::string> f1 = boost::make_ready_future(std::string("aaaa"));
|
||||
boost::future<int> f2 = boost::async(boost::launch::async, &p1b);
|
||||
boost::future<boost::csbl::tuple<boost::future<std::string>,boost::future<int> > > all = boost::when_any(boost::move(f1), boost::move(f2));
|
||||
boost::csbl::tuple<boost::future<std::string>,boost::future<int> > res = all.get();
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<1>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f2 = boost::make_ready_future(1);
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, &p1b);
|
||||
boost::future<boost::csbl::tuple<boost::future<int>,boost::future<int> > > all = boost::when_any(boost::move(f1), boost::move(f2));
|
||||
boost::csbl::tuple<boost::future<int>,boost::future<int> > res = all.get();
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<1>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::async(boost::launch::deferred, &p1);
|
||||
boost::future<int> f2 = boost::async(boost::launch::async, &p1b);
|
||||
boost::future<boost::csbl::tuple<boost::future<int>,boost::future<int> > > all = boost::when_any(boost::move(f1), boost::move(f2));
|
||||
boost::csbl::tuple<boost::future<int>,boost::future<int> > res = all.get();
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<1>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
|
||||
boost::future<int> f2 = boost::async(boost::launch::deferred, &p1b);
|
||||
boost::future<boost::csbl::tuple<boost::future<int>,boost::future<int> > > all = boost::when_any(boost::move(f1), boost::move(f2));
|
||||
boost::csbl::tuple<boost::future<int>,boost::future<int> > res = all.get();
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<0>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::csbl::get<1>(res).get() <<" " << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
#endif
|
||||
{
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::csbl::vector<boost::future<int> > v;
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
v.push_back(boost::async(boost::launch::async, &p1));
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
v.push_back(boost::async(boost::launch::async, &p1b));
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<boost::csbl::vector<boost::future<int> > > all = boost::when_any(v.begin(), v.end());
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::csbl::vector<boost::future<int> > res = all.get();
|
||||
BOOST_THREAD_LOG
|
||||
<< res[0].get() <<" " << BOOST_THREAD_END_LOG;
|
||||
BOOST_THREAD_LOG
|
||||
<< res[1].get() <<" " << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< "ERRORRRRR " << ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
BOOST_THREAD_LOG
|
||||
<< "MAIN>" << BOOST_THREAD_END_LOG;
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
#include <boost/thread/csbl/vector.hpp>
|
||||
using namespace boost;
|
||||
|
||||
void f( boost::csbl::vector<future<int> > &//vec
|
||||
, BOOST_THREAD_RV_REF(future<int>) //f
|
||||
) {
|
||||
}
|
||||
int main()
|
||||
{
|
||||
boost::csbl::vector<future<int> > vec;
|
||||
f(vec, make_ready_future(0));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
153
example/generic_executor_ref.cpp
Normal file
153
example/generic_executor_ref.cpp
Normal file
@@ -0,0 +1,153 @@
|
||||
// Copyright (C) 2014 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
#define BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
//#define BOOST_THREAD_USES_LOG
|
||||
#define BOOST_THREAD_USES_LOG_THREAD_ID
|
||||
#define BOOST_THREAD_QUEUE_DEPRECATE_OLD
|
||||
|
||||
#include <boost/thread/caller_context.hpp>
|
||||
#include <boost/thread/executors/basic_thread_pool.hpp>
|
||||
#include <boost/thread/executors/loop_executor.hpp>
|
||||
#include <boost/thread/executors/serial_executor.hpp>
|
||||
#include <boost/thread/executors/inline_executor.hpp>
|
||||
#include <boost/thread/executors/thread_executor.hpp>
|
||||
#include <boost/thread/executors/executor.hpp>
|
||||
#include <boost/thread/executors/executor_adaptor.hpp>
|
||||
#include <boost/thread/executor.hpp>
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
void p1()
|
||||
{
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
//boost::this_thread::sleep_for(boost::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
void p2()
|
||||
{
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
//boost::this_thread::sleep_for(boost::chrono::seconds(10));
|
||||
}
|
||||
|
||||
int f1()
|
||||
{
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
boost::this_thread::sleep_for(boost::chrono::seconds(1));
|
||||
return 1;
|
||||
}
|
||||
int f2(int i)
|
||||
{
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
boost::this_thread::sleep_for(boost::chrono::seconds(2));
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
void submit_some(boost::generic_executor_ref tp)
|
||||
{
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
tp.submit(&p2);
|
||||
}
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
tp.submit(&p1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void at_th_entry(boost::basic_thread_pool& )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int test_generic_executor_ref()
|
||||
{
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
boost::basic_thread_pool ea(4);
|
||||
submit_some( ea);
|
||||
{
|
||||
boost::future<int> t1 = boost::async(ea, &f1);
|
||||
boost::future<int> t2 = boost::async(ea, &f1);
|
||||
// std::cout << BOOST_CONTEXTOF << " t1= " << t1.get() << std::endl;
|
||||
// std::cout << BOOST_CONTEXTOF << " t2= " << t2.get() << std::endl;
|
||||
}
|
||||
submit_some(ea);
|
||||
{
|
||||
boost::basic_thread_pool ea3(1);
|
||||
boost::future<int> t1 = boost::async(ea3, &f1);
|
||||
boost::future<int> t2 = boost::async(ea3, &f1);
|
||||
//boost::future<int> t2 = boost::async(ea3, f2, 1); // todo this doesn't compiles yet on C++11
|
||||
//boost::future<int> t2 = boost::async(ea3, boost::bind(f2, 1)); // todo this doesn't compiles yet on C++98
|
||||
// std::cout << BOOST_CONTEXTOF << " t1= " << t1.get() << std::endl;
|
||||
// std::cout << BOOST_CONTEXTOF << " t2= " << t2.get() << std::endl;
|
||||
}
|
||||
submit_some(ea);
|
||||
}
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
{
|
||||
boost::loop_executor ea2;
|
||||
submit_some( ea2);
|
||||
ea2.run_queued_closures();
|
||||
}
|
||||
#if ! defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
{
|
||||
boost::basic_thread_pool ea1(4);
|
||||
boost::serial_executor ea2(ea1);
|
||||
submit_some(ea2);
|
||||
}
|
||||
#endif
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
{
|
||||
boost::inline_executor ea1;
|
||||
submit_some(ea1);
|
||||
}
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
{
|
||||
//boost::thread_executor ea1;
|
||||
//submit_some(ea1);
|
||||
}
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
{
|
||||
boost::basic_thread_pool ea(4, at_th_entry);
|
||||
boost::future<int> t1 = boost::async(ea, &f1);
|
||||
// std::cout << BOOST_CONTEXTOF << " t1= " << t1.get() << std::endl;
|
||||
}
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
std::cout << "ERROR= " << ex.what() << "" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << " ERROR= exception thrown" << std::endl;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
// std::cout << BOOST_CONTEXTOF << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
return test_generic_executor_ref();
|
||||
|
||||
|
||||
}
|
||||
67
example/lambda_future.cpp
Normal file
67
example/lambda_future.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
// Copyright (C) 2013 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
//#define BOOST_THREAD_USES_LOG
|
||||
#define BOOST_THREAD_USES_LOG_THREAD_ID
|
||||
|
||||
#include <boost/thread/detail/log.hpp>
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION \
|
||||
&& ! defined BOOST_NO_CXX11_LAMBDAS && ! (defined BOOST_MSVC && _MSC_VER < 1700)
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
const int number_of_tests = 100;
|
||||
BOOST_THREAD_LOG << "<MAIN" << BOOST_THREAD_END_LOG;
|
||||
|
||||
for (int i=0; i< number_of_tests; i++)
|
||||
try
|
||||
{
|
||||
{
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, []() {return 123;});
|
||||
int result = f1.get();
|
||||
BOOST_THREAD_LOG << "f1 " << result << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
{
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, []() {return 123;});
|
||||
boost::future<int> f2 = f1.then([](boost::future<int> f) {return 2*f.get(); });
|
||||
int result = f2.get();
|
||||
BOOST_THREAD_LOG << "f2 " << result << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
std::cout << "ERRORRRRR "<<ex.what() << "" << std::endl;
|
||||
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << " ERRORRRRR exception thrown" << std::endl;
|
||||
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
return 2;
|
||||
}
|
||||
BOOST_THREAD_LOG << "MAIN>" << BOOST_THREAD_END_LOG;
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
129
example/make_future.cpp
Normal file
129
example/make_future.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
// Copyright (C) 2012 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
exception_ptr make_exception_ptr(T v)
|
||||
{
|
||||
return copy_exception(v);
|
||||
}
|
||||
}
|
||||
|
||||
int p1() { return 5; }
|
||||
int& p1r() { static int i=0; return i; }
|
||||
|
||||
void p() { }
|
||||
|
||||
#if defined BOOST_THREAD_USES_MOVE
|
||||
boost::future<void> void_compute()
|
||||
{
|
||||
return BOOST_THREAD_MAKE_RV_REF(boost::make_ready_future());
|
||||
}
|
||||
#endif
|
||||
|
||||
boost::future<int> compute(int x)
|
||||
{
|
||||
if (x == 0) return boost::make_ready_future(0);
|
||||
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
if (x < 0) return boost::make_exceptional_future<int>(std::logic_error("Error"));
|
||||
#else
|
||||
if (x < 0) return boost::make_exceptional(std::logic_error("Error"));
|
||||
#endif
|
||||
//boost::future<int> f1 = boost::async([]() { return x+1; });
|
||||
boost::future<int> f1 = boost::async(p1);
|
||||
return boost::move(f1);
|
||||
}
|
||||
|
||||
boost::future<int&> compute_ref(int x)
|
||||
{
|
||||
static int i = 0;
|
||||
//if (x == 0) return boost::make_ready_future<int&>(i); //This must not compile as the type is deduced as boost::future<int>
|
||||
if (x == 0) return boost::make_ready_no_decay_future<int&>(i);
|
||||
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
if (x < 0) return boost::make_exceptional_future<int&>(std::logic_error("Error"));
|
||||
#else
|
||||
if (x < 0) return boost::make_exceptional(std::logic_error("Error"));
|
||||
#endif
|
||||
boost::future<int&> f1 = boost::async(p1r);
|
||||
return boost::move(f1);
|
||||
}
|
||||
|
||||
boost::shared_future<int> shared_compute(int x)
|
||||
{
|
||||
if (x == 0) return boost::make_ready_future(0).share();
|
||||
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
if (x < 0) return boost::make_exceptional_future<int>(std::logic_error("Error")).share();
|
||||
#else
|
||||
if (x < 0) return boost::make_exceptional(std::logic_error("Error"));
|
||||
#endif
|
||||
//boost::future<int> f1 = boost::async([]() { return x+1; });
|
||||
boost::shared_future<int> f1 = boost::async(&p1).share();
|
||||
return f1;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
const int number_of_tests = 100;
|
||||
for (int i=0; i< number_of_tests; i++)
|
||||
try
|
||||
{
|
||||
// {
|
||||
// std::cout << __FILE__ << " "<<__LINE__ << std::endl;
|
||||
// boost::future<int> f = boost::async(boost::launch::async, p1);
|
||||
// std::cout << i << " "<<f.get() << std::endl;
|
||||
// }
|
||||
#if defined BOOST_THREAD_USES_MOVE
|
||||
{
|
||||
std::cout << __FILE__ << " "<< __LINE__ << std::endl;
|
||||
boost::future<void> f = void_compute();
|
||||
f.get();
|
||||
}
|
||||
#endif
|
||||
{
|
||||
std::cout << __FILE__ << " "<< __LINE__ << std::endl;
|
||||
boost::future<int> f = compute(0);
|
||||
std::cout << f.get() << std::endl;
|
||||
}
|
||||
{
|
||||
std::cout << __FILE__ << " "<< __LINE__ << std::endl;
|
||||
boost::future<int&> f = compute_ref(0);
|
||||
std::cout << f.get() << std::endl;
|
||||
}
|
||||
// {
|
||||
// std::cout << __FILE__ << " "<< __LINE__ << std::endl;
|
||||
// boost::future<int> f = compute(2);
|
||||
// std::cout << f.get() << std::endl;
|
||||
// }
|
||||
{
|
||||
std::cout << __FILE__ << " "<< __LINE__ << std::endl;
|
||||
boost::shared_future<int> f = shared_compute(0);
|
||||
std::cout << f.get() << std::endl;
|
||||
}
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
std::cout << "ERRORRRRR "<<ex.what() << "" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << "ERRORRRRR "<<"ERRORRRRR exception thrown" << std::endl;
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <boost/thread/condition.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/recursive_mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
|
||||
namespace {
|
||||
const int ITERS = 100;
|
||||
@@ -20,7 +20,7 @@ template <typename M>
|
||||
class buffer_t
|
||||
{
|
||||
public:
|
||||
typedef typename M::scoped_lock scoped_lock;
|
||||
typedef boost::unique_lock<M> scoped_lock;
|
||||
|
||||
buffer_t(int n)
|
||||
: p(0), c(0), full(0), buf(n)
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
for (int n = 0; n < ITERS; ++n)
|
||||
{
|
||||
{
|
||||
boost::mutex::scoped_lock lock(io_mutex);
|
||||
boost::unique_lock<boost::mutex> lock(io_mutex);
|
||||
std::cout << "sending: " << n << std::endl;
|
||||
}
|
||||
get_buffer().send(n);
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
{
|
||||
int n = get_buffer().receive();
|
||||
{
|
||||
boost::mutex::scoped_lock lock(io_mutex);
|
||||
boost::unique_lock<boost::mutex> lock(io_mutex);
|
||||
std::cout << "received: " << n << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
|
||||
private:
|
||||
M mutex;
|
||||
boost::condition cond;
|
||||
boost::condition_variable_any cond;
|
||||
unsigned int p, c, full;
|
||||
std::vector<int> buf;
|
||||
};
|
||||
@@ -89,6 +89,7 @@ private:
|
||||
template <typename M>
|
||||
void do_test(M* dummy=0)
|
||||
{
|
||||
(void)dummy;
|
||||
typedef buffer_t<M> buffer_type;
|
||||
buffer_type::get_buffer();
|
||||
boost::thread thrd1(&buffer_type::do_receiver_thread);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
counter() : count(0) { }
|
||||
|
||||
int increment() {
|
||||
boost::mutex::scoped_lock scoped_lock(mutex);
|
||||
boost::unique_lock<boost::mutex> scoped_lock(mutex);
|
||||
return ++count;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ counter c;
|
||||
void change_count()
|
||||
{
|
||||
int i = c.increment();
|
||||
boost::mutex::scoped_lock scoped_lock(io_mutex);
|
||||
boost::unique_lock<boost::mutex> scoped_lock(io_mutex);
|
||||
std::cout << "count == " << i << std::endl;
|
||||
}
|
||||
|
||||
|
||||
63
example/not_interleaved.cpp
Normal file
63
example/not_interleaved.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
// (C) Copyright 2012 Howard Hinnant
|
||||
// (C) Copyright 2012 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// adapted from the example given by Howard Hinnant in
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/thread/scoped_thread.hpp>
|
||||
#include <boost/thread/externally_locked_stream.hpp>
|
||||
|
||||
void use_cerr(boost::externally_locked_stream<std::ostream> &mcerr)
|
||||
{
|
||||
using namespace boost;
|
||||
chrono::steady_clock::time_point tf = chrono::steady_clock::now() + chrono::seconds(10);
|
||||
while (chrono::steady_clock::now() < tf)
|
||||
{
|
||||
mcerr << "logging data to cerr\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(500));
|
||||
}
|
||||
}
|
||||
|
||||
void use_cout(boost::externally_locked_stream<std::ostream> &mcout)
|
||||
{
|
||||
using namespace boost;
|
||||
chrono::steady_clock::time_point tf = chrono::steady_clock::now() + chrono::seconds(5);
|
||||
while (chrono::steady_clock::now() < tf)
|
||||
{
|
||||
mcout << "logging data to cout\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(250));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost;
|
||||
|
||||
recursive_mutex terminal_mutex;
|
||||
|
||||
externally_locked_stream<std::ostream> mcerr(std::cerr, terminal_mutex);
|
||||
externally_locked_stream<std::ostream> mcout(std::cout, terminal_mutex);
|
||||
externally_locked_stream<std::istream> mcin(std::cin, terminal_mutex);
|
||||
|
||||
scoped_thread<> t1(boost::thread(use_cerr, boost::ref(mcerr)));
|
||||
scoped_thread<> t2(boost::thread(use_cout, boost::ref(mcout)));
|
||||
this_thread::sleep_for(chrono::seconds(2));
|
||||
std::string nm;
|
||||
{
|
||||
strict_lock<recursive_mutex> lk(terminal_mutex);
|
||||
std::ostream & gcout = mcout.get(lk);
|
||||
//std::istream & gcin = mcin.get(lk);
|
||||
gcout << "Enter name: ";
|
||||
//gcin >> nm;
|
||||
}
|
||||
t1.join();
|
||||
t2.join();
|
||||
mcout << nm << '\n';
|
||||
return 0;
|
||||
}
|
||||
|
||||
61
example/not_interleaved2.cpp
Normal file
61
example/not_interleaved2.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
// (C) Copyright 2012 Howard Hinnant
|
||||
// (C) Copyright 2012 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// adapted from the example given by Howard Hinnant in
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/thread/scoped_thread.hpp>
|
||||
#include <boost/thread/ostream_buffer.hpp>
|
||||
|
||||
void use_cerr()
|
||||
{
|
||||
using namespace boost;
|
||||
chrono::steady_clock::time_point tf = chrono::steady_clock::now() + chrono::seconds(5);
|
||||
int i = 0;
|
||||
while (chrono::steady_clock::now() < tf)
|
||||
{
|
||||
ostream_buffer<std::ostream> mcerr(std::cerr);
|
||||
mcerr.stream() << "logging data to cerr " << i++ << "\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(250));
|
||||
}
|
||||
}
|
||||
|
||||
void use_cout()
|
||||
{
|
||||
using namespace boost;
|
||||
chrono::steady_clock::time_point tf = chrono::steady_clock::now() + chrono::seconds(5);
|
||||
int i = 0;
|
||||
while (chrono::steady_clock::now() < tf)
|
||||
{
|
||||
ostream_buffer<std::ostream> mcout(std::cout);
|
||||
mcout.stream() << "logging data to cout " << i++ << "\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(500));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost;
|
||||
|
||||
scoped_thread<> t1(&use_cerr);
|
||||
scoped_thread<> t2(&use_cout);
|
||||
this_thread::sleep_for(chrono::seconds(2));
|
||||
std::string nm = "he, he\n";
|
||||
{
|
||||
ostream_buffer<std::ostream> mcout(std::cout);
|
||||
mcout.stream() << "Enter name: \n";
|
||||
}
|
||||
t1.join();
|
||||
t2.join();
|
||||
{
|
||||
ostream_buffer<std::ostream> mcout(std::cout);
|
||||
mcout.stream() << nm;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_THREAD_PROVIDES_ONCE_CXX11
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/once.hpp>
|
||||
#include <cassert>
|
||||
|
||||
int value=0;
|
||||
boost::once_flag once = BOOST_ONCE_INIT;
|
||||
#ifdef BOOST_THREAD_PROVIDES_ONCE_CXX11
|
||||
static boost::once_flag once;
|
||||
//static boost::once_flag once2 = BOOST_ONCE_INIT;
|
||||
#else
|
||||
static boost::once_flag once = BOOST_ONCE_INIT;
|
||||
//static boost::once_flag once2 = once;
|
||||
#endif
|
||||
|
||||
void init()
|
||||
{
|
||||
@@ -21,7 +29,7 @@ void thread_proc()
|
||||
boost::call_once(&init, once);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main()
|
||||
{
|
||||
boost::thread_group threads;
|
||||
for (int i=0; i<5; ++i)
|
||||
|
||||
102
example/parallel_accumulate.cpp
Normal file
102
example/parallel_accumulate.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
// Copyright (C) 2014 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
#define BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
#define BOOST_THREAD_USES_LOG_THREAD_ID
|
||||
#define BOOST_THREAD_QUEUE_DEPRECATE_OLD
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
|
||||
#include <boost/thread/executors/basic_thread_pool.hpp>
|
||||
#include <boost/thread/future.hpp>
|
||||
|
||||
#include <numeric>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
|
||||
|
||||
template<typename Iterator,typename T>
|
||||
struct accumulate_block
|
||||
{
|
||||
//typedef T result_type;
|
||||
T operator()(Iterator first,Iterator last)
|
||||
{
|
||||
return std::accumulate(first,last,T());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Iterator,typename T>
|
||||
T parallel_accumulate(Iterator first,Iterator last,T init)
|
||||
{
|
||||
unsigned long const length=std::distance(first,last);
|
||||
|
||||
if(!length)
|
||||
return init;
|
||||
|
||||
unsigned long const block_size=25;
|
||||
unsigned long const num_blocks=(length+block_size-1)/block_size;
|
||||
|
||||
boost::csbl::vector<boost::future<T> > futures(num_blocks-1);
|
||||
boost::basic_thread_pool pool;
|
||||
|
||||
Iterator block_start=first;
|
||||
for(unsigned long i=0;i<(num_blocks-1);++i)
|
||||
{
|
||||
Iterator block_end=block_start;
|
||||
std::advance(block_end,block_size);
|
||||
futures[i]=boost::async(pool, accumulate_block<Iterator,T>(), block_start, block_end);
|
||||
block_start=block_end;
|
||||
}
|
||||
T last_result=accumulate_block<Iterator,T>()(block_start,last);
|
||||
T result=init;
|
||||
for(unsigned long i=0;i<(num_blocks-1);++i)
|
||||
{
|
||||
result+=futures[i].get();
|
||||
}
|
||||
result += last_result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
const int s = 1001;
|
||||
std::vector<int> vec;
|
||||
vec.reserve(s);
|
||||
for (int i=0; i<s;++i)
|
||||
vec.push_back(1);
|
||||
int r = parallel_accumulate(vec.begin(), vec.end(),0);
|
||||
std::cout << r << std::endl;
|
||||
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
std::cout << "ERROR= " << ex.what() << "" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << " ERROR= exception thrown" << std::endl;
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
///#warning "This compiler doesn't supports variadics"
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
110
example/parallel_quick_sort.cpp
Normal file
110
example/parallel_quick_sort.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
// Copyright (C) 2012-2013 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
#define BOOST_THREAD_PROVIDES_EXECUTORS
|
||||
#define BOOST_THREAD_USES_LOG_THREAD_ID
|
||||
#define BOOST_THREAD_QUEUE_DEPRECATE_OLD
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
|
||||
#include <boost/thread/executors/basic_thread_pool.hpp>
|
||||
#include <boost/thread/future.hpp>
|
||||
#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
|
||||
|
||||
#include <numeric>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
|
||||
template<typename T>
|
||||
struct sorter
|
||||
{
|
||||
boost::basic_thread_pool pool;
|
||||
typedef std::list<T> return_type;
|
||||
|
||||
std::list<T> do_sort(std::list<T> chunk_data)
|
||||
{
|
||||
if(chunk_data.empty())
|
||||
{
|
||||
return chunk_data;
|
||||
}
|
||||
|
||||
std::list<T> result;
|
||||
result.splice(result.begin(),chunk_data, chunk_data.begin());
|
||||
T const& partition_val=*result.begin();
|
||||
|
||||
typename std::list<T>::iterator divide_point=
|
||||
std::partition(chunk_data.begin(), chunk_data.end(), [&](T const& val){return val<partition_val;});
|
||||
|
||||
std::list<T> new_lower_chunk;
|
||||
new_lower_chunk.splice(new_lower_chunk.end(), chunk_data, chunk_data.begin(), divide_point);
|
||||
|
||||
boost::future<std::list<T> > new_lower = boost::async(pool, &sorter::do_sort, this, std::move(new_lower_chunk));
|
||||
//boost::future<std::list<T> > new_lower = boost::async<return_type>(pool, &sorter::do_sort, this, std::move(new_lower_chunk));
|
||||
|
||||
std::list<T> new_higher(do_sort(chunk_data));
|
||||
|
||||
result.splice(result.end(),new_higher);
|
||||
while(!new_lower.is_ready())
|
||||
{
|
||||
pool.schedule_one_or_yield();
|
||||
}
|
||||
|
||||
result.splice(result.begin(),new_lower.get());
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
std::list<T> parallel_quick_sort(std::list<T>& input)
|
||||
{
|
||||
if(input.empty())
|
||||
{
|
||||
return input;
|
||||
}
|
||||
sorter<T> s;
|
||||
|
||||
return s.do_sort(input);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
const int s = 101;
|
||||
std::list<int> lst;
|
||||
for (int i=0; i<s;++i)
|
||||
lst.push_back(100-i);
|
||||
std::list<int> r = parallel_quick_sort(lst);
|
||||
for (std::list<int>::const_iterator it=r.begin(); it != r.end(); ++it)
|
||||
std::cout << *it << std::endl;
|
||||
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
std::cout << "ERROR= " << ex.what() << "" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cout << " ERROR= exception thrown" << std::endl;
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
//#warning "This compiler doesn't supports variadics and move semantics"
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
237
example/perf_condition_variable.cpp
Normal file
237
example/perf_condition_variable.cpp
Normal file
@@ -0,0 +1,237 @@
|
||||
// (C) Copyright 2012 Vicente J. Botet Escriba
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// This performance test is based on the performance test provided by maxim.yegorushkin
|
||||
// at https://svn.boost.org/trac/boost/ticket/7422
|
||||
|
||||
#define BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/chrono/stopwatches/simple_stopwatch.hpp>
|
||||
|
||||
#include <condition_variable>
|
||||
#include <future>
|
||||
#include <limits>
|
||||
#include <cstdio>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// class Stopwatch
|
||||
// {
|
||||
// public:
|
||||
// typedef long long rep;
|
||||
//
|
||||
// static rep now()
|
||||
// {
|
||||
// timespec ts;
|
||||
// if (clock_gettime(CLOCK_MONOTONIC, &ts)) abort();
|
||||
// return ts.tv_sec * rep(1000000000) + ts.tv_nsec;
|
||||
// }
|
||||
//
|
||||
// Stopwatch() :
|
||||
// start_(now())
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// rep elapsed() const
|
||||
// {
|
||||
// return now() - start_;
|
||||
// }
|
||||
//
|
||||
// private:
|
||||
// rep start_;
|
||||
// };
|
||||
|
||||
typedef boost::chrono::simple_stopwatch<> Stopwatch;
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct BoostTypes
|
||||
{
|
||||
typedef boost::condition_variable condition_variable;
|
||||
typedef boost::mutex mutex;
|
||||
typedef boost::mutex::scoped_lock scoped_lock;
|
||||
};
|
||||
|
||||
struct StdTypes
|
||||
{
|
||||
typedef std::condition_variable condition_variable;
|
||||
typedef std::mutex mutex;
|
||||
typedef std::unique_lock<std::mutex> scoped_lock;
|
||||
};
|
||||
|
||||
template <class Types>
|
||||
struct SharedData: Types
|
||||
{
|
||||
unsigned const iterations;
|
||||
unsigned counter;
|
||||
unsigned semaphore;
|
||||
typename Types::condition_variable cnd;
|
||||
typename Types::mutex mtx;
|
||||
Stopwatch::rep producer_time;
|
||||
|
||||
SharedData(unsigned iterations, unsigned consumers) :
|
||||
iterations(iterations), counter(), semaphore(consumers) // Initialize to the number of consumers. (*)
|
||||
, producer_time()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <class S>
|
||||
void producer_thread(S* shared_data)
|
||||
{
|
||||
Stopwatch sw;
|
||||
|
||||
unsigned const consumers = shared_data->semaphore; // (*)
|
||||
for (unsigned i = shared_data->iterations; i--;)
|
||||
{
|
||||
{
|
||||
typename S::scoped_lock lock(shared_data->mtx);
|
||||
// Wait till all consumers signal.
|
||||
while (consumers != shared_data->semaphore)
|
||||
{
|
||||
shared_data->cnd.wait(lock);
|
||||
}
|
||||
shared_data->semaphore = 0;
|
||||
// Signal consumers.
|
||||
++shared_data->counter;
|
||||
}
|
||||
shared_data->cnd.notify_all();
|
||||
}
|
||||
|
||||
shared_data->producer_time = sw.elapsed().count();
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void consumer_thread(S* shared_data)
|
||||
{
|
||||
unsigned counter = 0;
|
||||
while (counter != shared_data->iterations)
|
||||
{
|
||||
{
|
||||
typename S::scoped_lock lock(shared_data->mtx);
|
||||
// Wait till the producer signals.
|
||||
while (counter == shared_data->counter)
|
||||
{
|
||||
shared_data->cnd.wait(lock);
|
||||
}
|
||||
counter = shared_data->counter;
|
||||
// Signal the producer.
|
||||
++shared_data->semaphore;
|
||||
}
|
||||
shared_data->cnd.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <class Types>
|
||||
Stopwatch::rep benchmark_ping_pong(unsigned consumer_count)
|
||||
{
|
||||
typedef SharedData<Types> S;
|
||||
|
||||
auto best_producer_time = std::numeric_limits<Stopwatch::rep>::max BOOST_PREVENT_MACRO_SUBSTITUTION ();
|
||||
|
||||
std::vector<std::thread> consumers
|
||||
{ consumer_count };
|
||||
|
||||
// Run the benchmark 10 times and report the best time.
|
||||
for (int times = 10; times--;)
|
||||
{
|
||||
S shared_data
|
||||
{ 100000, consumer_count };
|
||||
|
||||
// Start the consumers.
|
||||
for (unsigned i = 0; i < consumer_count; ++i)
|
||||
consumers[i] = std::thread
|
||||
{ consumer_thread<S> , &shared_data };
|
||||
// Start the producer and wait till it finishes.
|
||||
std::thread
|
||||
{ producer_thread<S> , &shared_data }.join();
|
||||
// Wait till consumers finish.
|
||||
for (unsigned i = 0; i < consumer_count; ++i)
|
||||
consumers[i].join();
|
||||
|
||||
best_producer_time = std::min BOOST_PREVENT_MACRO_SUBSTITUTION (best_producer_time, shared_data.producer_time);
|
||||
|
||||
}
|
||||
|
||||
return best_producer_time;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} // namespace
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// sudo chrt -f 99 /usr/bin/time -f "\n***\ntime: %E\ncontext switches: %c\nwaits: %w" /home/max/otsquant/build/Linux-x86_64-64.g++-release/test/test
|
||||
|
||||
/*
|
||||
|
||||
Producer-consumer ping-pong tests. It aims to benchmark condition variables with and without
|
||||
thread cancellation support by comparing the time it took to complete the benchmark.
|
||||
|
||||
Condition variable with thread cancellation support is boost::condition_variable from
|
||||
boost-1.51. Without - std::condition_variable that comes with gcc-4.7.2.
|
||||
|
||||
One producer, one to CONSUMER_MAX consumers. The benchmark calls
|
||||
condition_variable::notify_all() without holding a mutex to maximize contention within this
|
||||
function. Each benchmark for a number of consumers is run three times and the best time is
|
||||
picked to get rid of outliers.
|
||||
|
||||
The results are reported for each benchmark for a number of consumers. The most important number
|
||||
is (std - boost) / std * 100. Positive numbers are when boost::condition_variable is faster,
|
||||
negative it is slower.
|
||||
|
||||
*/
|
||||
|
||||
int main()
|
||||
{
|
||||
std::printf("MAIN\n");
|
||||
enum
|
||||
{
|
||||
CONSUMER_MAX = 2
|
||||
};
|
||||
|
||||
struct
|
||||
{
|
||||
Stopwatch::rep boost, std;
|
||||
} best_times[CONSUMER_MAX] = {};
|
||||
|
||||
for (unsigned i = 1; i <= CONSUMER_MAX; ++i)
|
||||
{
|
||||
auto& b = best_times[i - 1];
|
||||
std::printf("STD: %d\n", i);
|
||||
b.std = benchmark_ping_pong<StdTypes> (i);
|
||||
std::printf("BOOST: %d\n", i);
|
||||
b.boost = benchmark_ping_pong<BoostTypes> (i);
|
||||
|
||||
std::printf("consumers: %4d\n", i);
|
||||
std::printf("best std producer time: %15.9fsec\n", b.std * 1e-9);
|
||||
std::printf("best boost producer time: %15.9fsec\n", b.boost * 1e-9);
|
||||
std::printf("(std - boost) / std: %7.2f%%\n", (b.std - b.boost) * 100. / b.std);
|
||||
}
|
||||
|
||||
printf("\ncsv:\n\n");
|
||||
printf("consumers,(std-boost)/std,std,boost\n");
|
||||
for (unsigned i = 1; i <= CONSUMER_MAX; ++i)
|
||||
{
|
||||
auto& b = best_times[i - 1];
|
||||
printf("%d,%f,%lld,%lld\n", i, (b.std - b.boost) * 100. / b.std, b.std, b.boost);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
72
example/perf_shared_mutex.cpp
Normal file
72
example/perf_shared_mutex.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
// (C) Copyright 2013 Andrey
|
||||
// (C) Copyright 2013 Vicente J. Botet Escriba
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// This performance test is based on the performance test provided by maxim.yegorushkin
|
||||
// at https://svn.boost.org/trac/boost/ticket/7422
|
||||
|
||||
#define BOOST_THREAD_USES_CHRONO
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/thread/lock_types.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include <boost/chrono/chrono_io.hpp>
|
||||
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
|
||||
using namespace boost;
|
||||
|
||||
shared_mutex mtx;
|
||||
const int cycles = 10000;
|
||||
|
||||
void shared()
|
||||
{
|
||||
int cycle(0);
|
||||
while (++cycle < cycles)
|
||||
{
|
||||
shared_lock<shared_mutex> lock(mtx);
|
||||
}
|
||||
}
|
||||
|
||||
void unique()
|
||||
{
|
||||
int cycle(0);
|
||||
while (++cycle < cycles)
|
||||
{
|
||||
unique_lock<shared_mutex> lock(mtx);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::chrono::high_resolution_clock::duration best_time(std::numeric_limits<boost::chrono::high_resolution_clock::duration::rep>::max BOOST_PREVENT_MACRO_SUBSTITUTION ());
|
||||
for (int i =100; i>0; --i) {
|
||||
boost::chrono::high_resolution_clock clock;
|
||||
boost::chrono::high_resolution_clock::time_point s1 = clock.now();
|
||||
thread t0(shared);
|
||||
thread t1(shared);
|
||||
thread t2(unique);
|
||||
//thread t11(shared);
|
||||
//thread t12(shared);
|
||||
//thread t13(shared);
|
||||
|
||||
t0.join();
|
||||
t1.join();
|
||||
t2.join();
|
||||
//t11.join();
|
||||
// t12.join();
|
||||
// t13.join();
|
||||
boost::chrono::high_resolution_clock::time_point f1 = clock.now();
|
||||
//std::cout << " Time spent:" << (f1 - s1) << std::endl;
|
||||
best_time = std::min BOOST_PREVENT_MACRO_SUBSTITUTION (best_time, f1 - s1);
|
||||
|
||||
}
|
||||
std::cout << "Best Time spent:" << best_time << std::endl;
|
||||
std::cout << "Time spent/cycle:" << best_time/cycles/3 << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
147
example/producer_consumer.cpp
Normal file
147
example/producer_consumer.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
// (C) Copyright 2012 Howard Hinnant
|
||||
// (C) Copyright 2012 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// adapted from the example given by Howard Hinnant in
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
#define BOOST_THREAD_QUEUE_DEPRECATE_OLD
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
#include <iostream>
|
||||
#include <boost/thread/scoped_thread.hpp>
|
||||
#ifdef XXXX
|
||||
#include <boost/thread/externally_locked_stream.hpp>
|
||||
typedef boost::externally_locked_stream<std::ostream> the_ostream;
|
||||
#else
|
||||
typedef std::ostream the_ostream;
|
||||
typedef std::istream the_istream;
|
||||
#endif
|
||||
#include <boost/thread/concurrent_queues/sync_queue.hpp>
|
||||
|
||||
void producer(the_ostream &mos, boost::sync_queue<int> & sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
sbq.push(i);
|
||||
//sbq << i;
|
||||
mos << "push(" << i << ") "<< sbq.size()<<"\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(200));
|
||||
}
|
||||
}
|
||||
catch(sync_queue_is_closed&)
|
||||
{
|
||||
mos << "closed !!!\n";
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
|
||||
void consumer(
|
||||
the_ostream &mos,
|
||||
boost::sync_queue<int> & sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
int r;
|
||||
sbq.pull(r);
|
||||
//sbq >> r;
|
||||
mos << i << " pull(" << r << ") "<< sbq.size()<<"\n";
|
||||
|
||||
this_thread::sleep_for(chrono::milliseconds(250));
|
||||
}
|
||||
}
|
||||
catch(sync_queue_is_closed&)
|
||||
{
|
||||
mos << "closed !!!\n";
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
void consumer2(the_ostream &mos, boost::sync_queue<int> & sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
int r;
|
||||
queue_op_status st = sbq.try_pull(r);
|
||||
if (queue_op_status::closed == st) break;
|
||||
if (queue_op_status::success == st) {
|
||||
mos << i << " pull(" << r << ")\n";
|
||||
}
|
||||
this_thread::sleep_for(chrono::milliseconds(250));
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
void consumer3(the_ostream &mos, boost::sync_queue<int> & sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
int r;
|
||||
queue_op_status res = sbq.wait_pull(r);
|
||||
if (res==queue_op_status::closed) break;
|
||||
mos << i << " wait_pull(" << r << ")\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(250));
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost;
|
||||
|
||||
#ifdef XXXX
|
||||
recursive_mutex terminal_mutex;
|
||||
|
||||
externally_locked_stream<std::ostream> mcerr(std::cerr, terminal_mutex);
|
||||
externally_locked_stream<std::ostream> mcout(std::cout, terminal_mutex);
|
||||
externally_locked_stream<std::istream> mcin(std::cin, terminal_mutex);
|
||||
#else
|
||||
the_ostream &mcerr = std::cout;
|
||||
the_ostream &mcout = std::cerr;
|
||||
//the_istream &mcin = std::cin;
|
||||
#endif
|
||||
|
||||
sync_queue<int> sbq;
|
||||
|
||||
{
|
||||
mcout << "begin of main" << std::endl;
|
||||
scoped_thread<> t11(boost::thread(producer, boost::ref(mcerr), boost::ref(sbq)));
|
||||
scoped_thread<> t12(boost::thread(producer, boost::ref(mcerr), boost::ref(sbq)));
|
||||
scoped_thread<> t2(boost::thread(consumer, boost::ref(mcout), boost::ref(sbq)));
|
||||
|
||||
this_thread::sleep_for(chrono::seconds(1));
|
||||
|
||||
mcout << "closed()" << std::endl;
|
||||
sbq.close();
|
||||
mcout << "closed()" << std::endl;
|
||||
|
||||
} // all threads joined here.
|
||||
mcout << "end of main" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
150
example/producer_consumer2.cpp
Normal file
150
example/producer_consumer2.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
// (C) Copyright 2014 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// adapted from the example given by Howard Hinnant in
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
//#define BOOST_THREAD_QUEUE_DEPRECATE_OLD
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
#include <iostream>
|
||||
#include <boost/thread/scoped_thread.hpp>
|
||||
#ifdef XXXX
|
||||
#include <boost/thread/externally_locked_stream.hpp>
|
||||
typedef boost::externally_locked_stream<std::ostream> the_ostream;
|
||||
#else
|
||||
typedef std::ostream the_ostream;
|
||||
typedef std::istream the_istream;
|
||||
#endif
|
||||
#include <boost/thread/concurrent_queues/sync_queue.hpp>
|
||||
#include <boost/thread/concurrent_queues/queue_adaptor.hpp>
|
||||
#include <boost/thread/concurrent_queues/queue_views.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
|
||||
void producer(the_ostream &mos, boost::queue_back<int> sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
sbq.push(i);
|
||||
//sbq << i;
|
||||
mos << "push(" << i << ") " << sbq.size() <<"\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(200));
|
||||
}
|
||||
}
|
||||
catch(sync_queue_is_closed&)
|
||||
{
|
||||
mos << "closed !!!\n";
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
|
||||
void consumer(
|
||||
the_ostream &mos,
|
||||
boost::queue_front<int> sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
int r;
|
||||
sbq.pull(r);
|
||||
//sbq >> r;
|
||||
mos << i << " pull(" << r << ") " << sbq.size() <<"\n";
|
||||
|
||||
this_thread::sleep_for(chrono::milliseconds(250));
|
||||
}
|
||||
}
|
||||
catch(sync_queue_is_closed&)
|
||||
{
|
||||
mos << "closed !!!\n";
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
void consumer2(the_ostream &mos, boost::queue_front<int> sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
int r;
|
||||
queue_op_status st = sbq.try_pull(r);
|
||||
if (queue_op_status::closed == st) break;
|
||||
if (queue_op_status::success == st) {
|
||||
mos << i << " try_pull(" << r << ")\n";
|
||||
}
|
||||
this_thread::sleep_for(chrono::milliseconds(250));
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
void consumer3(the_ostream &mos, boost::queue_front<int> sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
int r;
|
||||
queue_op_status res = sbq.wait_pull(r);
|
||||
if (res==queue_op_status::closed) break;
|
||||
mos << i << " wait_pull(" << r << ")\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(250));
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost;
|
||||
|
||||
#ifdef XXXX
|
||||
recursive_mutex terminal_mutex;
|
||||
|
||||
externally_locked_stream<std::ostream> mcerr(std::cerr, terminal_mutex);
|
||||
externally_locked_stream<std::ostream> mcout(std::cout, terminal_mutex);
|
||||
externally_locked_stream<std::istream> mcin(std::cin, terminal_mutex);
|
||||
#else
|
||||
the_ostream &mcerr = std::cout;
|
||||
the_ostream &mcout = std::cerr;
|
||||
//the_istream &mcin = std::cin;
|
||||
#endif
|
||||
|
||||
queue_adaptor<sync_queue<int> > sbq;
|
||||
|
||||
{
|
||||
mcout << "begin of main" << std::endl;
|
||||
scoped_thread<> t11(boost::thread(producer, boost::ref(mcerr), concurrent::queue_back<int>(sbq)));
|
||||
scoped_thread<> t12(boost::thread(producer, boost::ref(mcerr), concurrent::queue_back<int>(sbq)));
|
||||
scoped_thread<> t2(boost::thread(consumer, boost::ref(mcout), concurrent::queue_front<int>(sbq)));
|
||||
|
||||
this_thread::sleep_for(chrono::seconds(1));
|
||||
|
||||
mcout << "closed()" << std::endl;
|
||||
sbq.close();
|
||||
mcout << "closed()" << std::endl;
|
||||
|
||||
} // all threads joined here.
|
||||
mcout << "end of main" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
146
example/producer_consumer_bounded.cpp
Normal file
146
example/producer_consumer_bounded.cpp
Normal file
@@ -0,0 +1,146 @@
|
||||
// (C) Copyright 2012 Howard Hinnant
|
||||
// (C) Copyright 2012 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// adapted from the example given by Howard Hinnant in
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
#define BOOST_THREAD_QUEUE_DEPRECATE_OLD
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
//#define XXXX
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/thread/scoped_thread.hpp>
|
||||
#ifdef XXXX
|
||||
#include <boost/thread/externally_locked_stream.hpp>
|
||||
typedef boost::externally_locked_stream<std::ostream> the_ostream;
|
||||
#else
|
||||
typedef std::ostream the_ostream;
|
||||
typedef std::istream the_istream;
|
||||
#endif
|
||||
|
||||
#include <boost/thread/sync_bounded_queue.hpp>
|
||||
|
||||
void producer(the_ostream &/*mos*/, boost::sync_bounded_queue<int> & sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
sbq.push_back(i);
|
||||
//sbq << i;
|
||||
//mos << "push_back(" << i << ") "<< sbq.size()<<"\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(200));
|
||||
}
|
||||
}
|
||||
catch(sync_queue_is_closed&)
|
||||
{
|
||||
//mos << "closed !!!\n";
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
//mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
|
||||
void consumer(the_ostream &/*mos*/, boost::sync_bounded_queue<int> & sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
int r;
|
||||
sbq.pull_front(r);
|
||||
//sbq >> r;
|
||||
//mos << i << " pull_front(" << r << ") "<< sbq.size()<<"\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(250));
|
||||
}
|
||||
}
|
||||
catch(sync_queue_is_closed&)
|
||||
{
|
||||
//mos << "closed !!!\n";
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
//mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
void consumer2(the_ostream &/*mos*/, boost::sync_bounded_queue<int> & sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
int r;
|
||||
queue_op_status st = sbq.try_pull_front(r);
|
||||
if (queue_op_status::closed == st) break;
|
||||
if (queue_op_status::success == st) {
|
||||
//mos << i << " pull(" << r << ")\n";
|
||||
}
|
||||
this_thread::sleep_for(chrono::milliseconds(250));
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
//mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
//void consumer3(the_ostream &mos, boost::sync_bounded_queue<int> & sbq)
|
||||
//{
|
||||
// using namespace boost;
|
||||
// bool closed=false;
|
||||
// try {
|
||||
// for(int i=0; ;++i)
|
||||
// {
|
||||
// int r;
|
||||
// queue_op_status res = sbq.wait_and_pull(r);
|
||||
// if (res==queue_op_status::closed) break;
|
||||
// //mos << i << " wait_and_pull(" << r << ")\n";
|
||||
// this_thread::sleep_for(chrono::milliseconds(250));
|
||||
// }
|
||||
// }
|
||||
// catch(...)
|
||||
// {
|
||||
// //mos << "exception !!!\n";
|
||||
// }
|
||||
//}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost;
|
||||
#ifdef XXXX
|
||||
recursive_mutex terminal_mutex;
|
||||
|
||||
externally_locked_stream<std::ostream> mcerr(std::cerr, terminal_mutex);
|
||||
externally_locked_stream<std::ostream> mcout(std::cout, terminal_mutex);
|
||||
externally_locked_stream<std::istream> mcin(std::cin, terminal_mutex);
|
||||
#else
|
||||
the_ostream &mcerr = std::cout;
|
||||
the_ostream &mcout = std::cerr;
|
||||
//the_istream &mcin = std::cin;
|
||||
#endif
|
||||
|
||||
sync_bounded_queue<int> sbq(10);
|
||||
|
||||
{
|
||||
mcout << "begin of main" << std::endl;
|
||||
scoped_thread<> t11(boost::thread(producer, boost::ref(mcerr), boost::ref(sbq)));
|
||||
scoped_thread<> t12(boost::thread(producer, boost::ref(mcerr), boost::ref(sbq)));
|
||||
scoped_thread<> t2(boost::thread(consumer, boost::ref(mcout), boost::ref(sbq)));
|
||||
|
||||
this_thread::sleep_for(chrono::seconds(1));
|
||||
|
||||
sbq.close();
|
||||
mcout << "closed()" << std::endl;
|
||||
|
||||
} // all threads joined here.
|
||||
mcout << "end of main" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/thread/recursive_mutex.hpp>
|
||||
@@ -14,12 +14,12 @@ public:
|
||||
counter() : count(0) { }
|
||||
|
||||
int add(int val) {
|
||||
boost::recursive_mutex::scoped_lock scoped_lock(mutex);
|
||||
boost::unique_lock<boost::recursive_mutex> scoped_lock(mutex);
|
||||
count += val;
|
||||
return count;
|
||||
}
|
||||
int increment() {
|
||||
boost::recursive_mutex::scoped_lock scoped_lock(mutex);
|
||||
boost::unique_lock<boost::recursive_mutex> scoped_lock(mutex);
|
||||
return add(1);
|
||||
}
|
||||
|
||||
|
||||
93
example/scoped_thread.cpp
Normal file
93
example/scoped_thread.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
// (C) Copyright 2009-2012 Anthony Williams
|
||||
// (C) Copyright 2012 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_THREAD_VERSION 3
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/thread/scoped_thread.hpp>
|
||||
|
||||
void do_something(int& i)
|
||||
{
|
||||
++i;
|
||||
}
|
||||
void f(int, int)
|
||||
{
|
||||
}
|
||||
|
||||
struct func
|
||||
{
|
||||
int& i;
|
||||
|
||||
func(int& i_) :
|
||||
i(i_)
|
||||
{
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
for (unsigned j = 0; j < 1000000; ++j)
|
||||
{
|
||||
do_something(i);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void do_something_in_current_thread()
|
||||
{
|
||||
}
|
||||
|
||||
//void do_something_with_current_thread(boost::thread&& th)
|
||||
//{
|
||||
// th.join();
|
||||
//}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
int some_local_state;
|
||||
boost::strict_scoped_thread<> t( (boost::thread(func(some_local_state))));
|
||||
|
||||
do_something_in_current_thread();
|
||||
}
|
||||
{
|
||||
int some_local_state;
|
||||
boost::thread t(( func(some_local_state) ));
|
||||
boost::strict_scoped_thread<> g( (boost::move(t)) );
|
||||
|
||||
do_something_in_current_thread();
|
||||
}
|
||||
// {
|
||||
// int some_local_state;
|
||||
// boost::thread t(( func(some_local_state) ));
|
||||
// boost::strict_scoped_thread<> g( (boost::move(t)) );
|
||||
//
|
||||
// do_something_in_current_thread();
|
||||
// do_something_with_current_thread(boost::thread(g));
|
||||
// }
|
||||
{
|
||||
int some_local_state;
|
||||
boost::scoped_thread<> t( (boost::thread(func(some_local_state))));
|
||||
|
||||
if (t.joinable())
|
||||
t.join();
|
||||
else
|
||||
do_something_in_current_thread();
|
||||
}
|
||||
{
|
||||
int some_local_state;
|
||||
boost::thread t(( func(some_local_state) ));
|
||||
boost::scoped_thread<> g( (boost::move(t)) );
|
||||
t.detach();
|
||||
|
||||
do_something_in_current_thread();
|
||||
}
|
||||
{
|
||||
boost::scoped_thread<> g( &f, 1, 2 );
|
||||
do_something_in_current_thread();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
144
example/shared_monitor.cpp
Normal file
144
example/shared_monitor.cpp
Normal file
@@ -0,0 +1,144 @@
|
||||
// Copyright (C) 2012 Vicente J. Botet Escriba
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/thread/lock_algorithms.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#if defined BOOST_THREAD_DONT_USE_CHRONO
|
||||
#include <boost/chrono/chrono_io.hpp>
|
||||
#endif
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
#define EXCLUSIVE 1
|
||||
#define SHARED 2
|
||||
|
||||
#define MODE SHARED
|
||||
|
||||
class A
|
||||
{
|
||||
#if MODE == EXCLUSIVE
|
||||
typedef boost::mutex mutex_type;
|
||||
#elif MODE == SHARED
|
||||
typedef boost::shared_mutex mutex_type;
|
||||
#else
|
||||
#error MODE not set
|
||||
#endif
|
||||
typedef std::vector<double> C;
|
||||
mutable mutex_type mut_;
|
||||
C data_;
|
||||
public:
|
||||
A() : data_(10000000) {}
|
||||
A(const A& a);
|
||||
A& operator=(const A& a);
|
||||
|
||||
void compute(const A& x, const A& y);
|
||||
};
|
||||
|
||||
A::A(const A& a)
|
||||
{
|
||||
#if MODE == EXCLUSIVE
|
||||
boost::unique_lock<mutex_type> lk(a.mut_);
|
||||
#elif MODE == SHARED
|
||||
boost::shared_lock<mutex_type> lk(a.mut_);
|
||||
#else
|
||||
#error MODE not set
|
||||
#endif
|
||||
data_ = a.data_;
|
||||
}
|
||||
|
||||
A&
|
||||
A::operator=(const A& a)
|
||||
{
|
||||
if (this != &a)
|
||||
{
|
||||
boost::unique_lock<mutex_type> lk1(mut_, boost::defer_lock);
|
||||
#if MODE == EXCLUSIVE
|
||||
boost::unique_lock<mutex_type> lk2(a.mut_, boost::defer_lock);
|
||||
#elif MODE == SHARED
|
||||
boost::shared_lock<mutex_type> lk2(a.mut_, boost::defer_lock);
|
||||
#else
|
||||
#error MODE not set
|
||||
#endif
|
||||
boost::lock(lk1, lk2);
|
||||
data_ = a.data_;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
A::compute(const A& x, const A& y)
|
||||
{
|
||||
boost::unique_lock<mutex_type> lk1(mut_, boost::defer_lock);
|
||||
#if MODE == EXCLUSIVE
|
||||
boost::unique_lock<mutex_type> lk2(x.mut_, boost::defer_lock);
|
||||
boost::unique_lock<mutex_type> lk3(y.mut_, boost::defer_lock);
|
||||
#elif MODE == SHARED
|
||||
boost::shared_lock<mutex_type> lk2(x.mut_, boost::defer_lock);
|
||||
boost::shared_lock<mutex_type> lk3(y.mut_, boost::defer_lock);
|
||||
#else
|
||||
#error MODE not set
|
||||
#endif
|
||||
boost::lock(lk1, lk2, lk3);
|
||||
assert(data_.size() == x.data_.size());
|
||||
assert(data_.size() == y.data_.size());
|
||||
for (unsigned i = 0; i < data_.size(); ++i)
|
||||
data_[i] = (x.data_[i] + y.data_[i]) / 2;
|
||||
}
|
||||
|
||||
A a1;
|
||||
A a2;
|
||||
|
||||
void test_s()
|
||||
{
|
||||
A la3 = a1;
|
||||
for (int i = 0; i < 150; ++i)
|
||||
{
|
||||
la3.compute(a1, a2);
|
||||
}
|
||||
}
|
||||
|
||||
void test_w()
|
||||
{
|
||||
A la3 = a1;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
la3.compute(a1, a2);
|
||||
a1 = la3;
|
||||
a2 = la3;
|
||||
#if defined BOOST_THREAD_DONT_USE_CHRONO
|
||||
boost::this_thread::sleep_for(boost::chrono::seconds(1));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
#if defined BOOST_THREAD_DONT_USE_CHRONO
|
||||
typedef boost::chrono::high_resolution_clock Clock;
|
||||
typedef boost::chrono::duration<double> sec;
|
||||
Clock::time_point t0 = Clock::now();
|
||||
#endif
|
||||
std::vector<boost::thread*> v;
|
||||
boost::thread thw(test_w);
|
||||
v.push_back(&thw);
|
||||
boost::thread thr0(test_w);
|
||||
v.push_back(&thr0);
|
||||
boost::thread thr1(test_w);
|
||||
v.push_back(&thr1);
|
||||
boost::thread thr2(test_w);
|
||||
v.push_back(&thr2);
|
||||
boost::thread thr3(test_w);
|
||||
v.push_back(&thr3);
|
||||
for (std::size_t i = 0; i < v.size(); ++i)
|
||||
v[i]->join();
|
||||
#if defined BOOST_THREAD_DONT_USE_CHRONO
|
||||
Clock::time_point t1 = Clock::now();
|
||||
std::cout << sec(t1-t0) << '\n';
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
746
example/shared_mutex.cpp
Normal file
746
example/shared_mutex.cpp
Normal file
@@ -0,0 +1,746 @@
|
||||
// Copyright (C) 2012 Vicente J. Botet Escriba
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS
|
||||
#define BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION
|
||||
#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/thread/lock_algorithms.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include <vector>
|
||||
|
||||
#if defined BOOST_THREAD_USES_CHRONO
|
||||
#include <boost/chrono/chrono_io.hpp>
|
||||
|
||||
|
||||
enum {reading, writing};
|
||||
int state = reading;
|
||||
|
||||
#if 1
|
||||
|
||||
boost::mutex&
|
||||
cout_mut()
|
||||
{
|
||||
static boost::mutex m;
|
||||
return m;
|
||||
}
|
||||
|
||||
void
|
||||
print(const char* tag, unsigned count, char ch)
|
||||
{
|
||||
boost::lock_guard<boost::mutex> _(cout_mut());
|
||||
std::cout << tag << count << ch;
|
||||
}
|
||||
|
||||
#elif 0
|
||||
|
||||
boost::recursive_mutex&
|
||||
cout_mut()
|
||||
{
|
||||
static boost::recursive_mutex m;
|
||||
return m;
|
||||
}
|
||||
|
||||
void print() {}
|
||||
|
||||
template <class A0, class ...Args>
|
||||
void
|
||||
print(const A0& a0, const Args& ...args)
|
||||
{
|
||||
boost::lock_guard<boost::recursive_mutex> _(cout_mut());
|
||||
std::cout << a0;
|
||||
print(args...);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template <class A0, class A1, class A2>
|
||||
void
|
||||
print(const A0&, const A1& a1, const A2&)
|
||||
{
|
||||
assert(a1 > 10000);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
namespace S
|
||||
{
|
||||
|
||||
boost::shared_mutex mut;
|
||||
|
||||
void reader()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
mut.lock_shared();
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_shared();
|
||||
}
|
||||
print("reader = ", count, '\n');
|
||||
}
|
||||
|
||||
void writer()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
mut.lock();
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
++count;
|
||||
mut.unlock();
|
||||
}
|
||||
print("writer = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_reader()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_shared())
|
||||
{
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_shared();
|
||||
}
|
||||
}
|
||||
print("try_reader = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_writer()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock())
|
||||
{
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
++count;
|
||||
mut.unlock();
|
||||
}
|
||||
}
|
||||
print("try_writer = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_for_reader()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_shared_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_shared();
|
||||
}
|
||||
}
|
||||
print("try_for_reader = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_for_writer()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
++count;
|
||||
mut.unlock();
|
||||
}
|
||||
}
|
||||
print("try_for_writer = ", count, '\n');
|
||||
}
|
||||
|
||||
void
|
||||
test_shared_mutex()
|
||||
{
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
{
|
||||
boost::thread t1(reader);
|
||||
boost::thread t2(writer);
|
||||
boost::thread t3(reader);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
{
|
||||
boost::thread t1(try_reader);
|
||||
boost::thread t2(try_writer);
|
||||
boost::thread t3(try_reader);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
{
|
||||
boost::thread t1(try_for_reader);
|
||||
boost::thread t2(try_for_writer);
|
||||
boost::thread t3(try_for_reader);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace U
|
||||
{
|
||||
|
||||
boost::upgrade_mutex mut;
|
||||
|
||||
void reader()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
mut.lock_shared();
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_shared();
|
||||
}
|
||||
print("reader = ", count, '\n');
|
||||
}
|
||||
|
||||
void writer()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
mut.lock();
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
++count;
|
||||
mut.unlock();
|
||||
}
|
||||
print("writer = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_reader()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_shared())
|
||||
{
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_shared();
|
||||
}
|
||||
}
|
||||
print("try_reader = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_writer()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock())
|
||||
{
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
++count;
|
||||
mut.unlock();
|
||||
}
|
||||
}
|
||||
print("try_writer = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_for_reader()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_shared_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_shared();
|
||||
}
|
||||
}
|
||||
print("try_for_reader = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_for_writer()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
++count;
|
||||
mut.unlock();
|
||||
}
|
||||
}
|
||||
print("try_for_writer = ", count, '\n');
|
||||
}
|
||||
|
||||
void upgradable()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
mut.lock_upgrade();
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_upgrade();
|
||||
}
|
||||
print("upgradable = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_upgradable()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_upgrade())
|
||||
{
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_upgrade();
|
||||
}
|
||||
}
|
||||
print("try_upgradable = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_for_upgradable()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_upgrade_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_upgrade();
|
||||
}
|
||||
}
|
||||
print("try_for_upgradable = ", count, '\n');
|
||||
}
|
||||
|
||||
void clockwise()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
mut.lock_shared();
|
||||
assert(state == reading);
|
||||
if (mut.try_unlock_shared_and_lock())
|
||||
{
|
||||
state = writing;
|
||||
}
|
||||
else if (mut.try_unlock_shared_and_lock_upgrade())
|
||||
{
|
||||
assert(state == reading);
|
||||
mut.unlock_upgrade_and_lock();
|
||||
state = writing;
|
||||
}
|
||||
else
|
||||
{
|
||||
mut.unlock_shared();
|
||||
continue;
|
||||
}
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
mut.unlock_and_lock_upgrade();
|
||||
assert(state == reading);
|
||||
mut.unlock_upgrade_and_lock_shared();
|
||||
assert(state == reading);
|
||||
mut.unlock_shared();
|
||||
++count;
|
||||
}
|
||||
print("clockwise = ", count, '\n');
|
||||
}
|
||||
|
||||
void counter_clockwise()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
mut.lock_upgrade();
|
||||
assert(state == reading);
|
||||
mut.unlock_upgrade_and_lock();
|
||||
assert(state == reading);
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
mut.unlock_and_lock_shared();
|
||||
assert(state == reading);
|
||||
mut.unlock_shared();
|
||||
++count;
|
||||
}
|
||||
print("counter_clockwise = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_clockwise()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_shared())
|
||||
{
|
||||
assert(state == reading);
|
||||
if (mut.try_unlock_shared_and_lock())
|
||||
{
|
||||
state = writing;
|
||||
}
|
||||
else if (mut.try_unlock_shared_and_lock_upgrade())
|
||||
{
|
||||
assert(state == reading);
|
||||
mut.unlock_upgrade_and_lock();
|
||||
state = writing;
|
||||
}
|
||||
else
|
||||
{
|
||||
mut.unlock_shared();
|
||||
continue;
|
||||
}
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
mut.unlock_and_lock_upgrade();
|
||||
assert(state == reading);
|
||||
mut.unlock_upgrade_and_lock_shared();
|
||||
assert(state == reading);
|
||||
mut.unlock_shared();
|
||||
++count;
|
||||
}
|
||||
}
|
||||
print("try_clockwise = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_for_clockwise()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_shared_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
assert(state == reading);
|
||||
if (mut.try_unlock_shared_and_lock_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
state = writing;
|
||||
}
|
||||
else if (mut.try_unlock_shared_and_lock_upgrade_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
assert(state == reading);
|
||||
mut.unlock_upgrade_and_lock();
|
||||
state = writing;
|
||||
}
|
||||
else
|
||||
{
|
||||
mut.unlock_shared();
|
||||
continue;
|
||||
}
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
mut.unlock_and_lock_upgrade();
|
||||
assert(state == reading);
|
||||
mut.unlock_upgrade_and_lock_shared();
|
||||
assert(state == reading);
|
||||
mut.unlock_shared();
|
||||
++count;
|
||||
}
|
||||
}
|
||||
print("try_for_clockwise = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_counter_clockwise()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_upgrade())
|
||||
{
|
||||
assert(state == reading);
|
||||
if (mut.try_unlock_upgrade_and_lock())
|
||||
{
|
||||
assert(state == reading);
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
mut.unlock_and_lock_shared();
|
||||
assert(state == reading);
|
||||
mut.unlock_shared();
|
||||
++count;
|
||||
}
|
||||
else
|
||||
{
|
||||
mut.unlock_upgrade();
|
||||
}
|
||||
}
|
||||
}
|
||||
print("try_counter_clockwise = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_for_counter_clockwise()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_upgrade_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
assert(state == reading);
|
||||
if (mut.try_unlock_upgrade_and_lock_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
assert(state == reading);
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
mut.unlock_and_lock_shared();
|
||||
assert(state == reading);
|
||||
mut.unlock_shared();
|
||||
++count;
|
||||
}
|
||||
else
|
||||
{
|
||||
mut.unlock_upgrade();
|
||||
}
|
||||
}
|
||||
}
|
||||
print("try_for_counter_clockwise = ", count, '\n');
|
||||
}
|
||||
|
||||
void
|
||||
test_upgrade_mutex()
|
||||
{
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
{
|
||||
boost::thread t1(reader);
|
||||
boost::thread t2(writer);
|
||||
boost::thread t3(reader);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
{
|
||||
boost::thread t1(try_reader);
|
||||
boost::thread t2(try_writer);
|
||||
boost::thread t3(try_reader);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
{
|
||||
boost::thread t1(try_for_reader);
|
||||
boost::thread t2(try_for_writer);
|
||||
boost::thread t3(try_for_reader);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
{
|
||||
boost::thread t1(reader);
|
||||
boost::thread t2(writer);
|
||||
boost::thread t3(upgradable);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
{
|
||||
boost::thread t1(reader);
|
||||
boost::thread t2(writer);
|
||||
boost::thread t3(try_upgradable);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
{
|
||||
boost::thread t1(reader);
|
||||
boost::thread t2(writer);
|
||||
boost::thread t3(try_for_upgradable);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
{
|
||||
state = reading;
|
||||
boost::thread t1(clockwise);
|
||||
boost::thread t2(counter_clockwise);
|
||||
boost::thread t3(clockwise);
|
||||
boost::thread t4(counter_clockwise);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
t4.join();
|
||||
}
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
{
|
||||
state = reading;
|
||||
boost::thread t1(try_clockwise);
|
||||
boost::thread t2(try_counter_clockwise);
|
||||
t1.join();
|
||||
t2.join();
|
||||
}
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
// {
|
||||
// state = reading;
|
||||
// boost::thread t1(try_for_clockwise);
|
||||
// boost::thread t2(try_for_counter_clockwise);
|
||||
// t1.join();
|
||||
// t2.join();
|
||||
// }
|
||||
// std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Assignment
|
||||
{
|
||||
|
||||
class A
|
||||
{
|
||||
typedef boost::upgrade_mutex mutex_type;
|
||||
typedef boost::shared_lock<mutex_type> SharedLock;
|
||||
typedef boost::upgrade_lock<mutex_type> UpgradeLock;
|
||||
typedef boost::unique_lock<mutex_type> Lock;
|
||||
|
||||
mutable mutex_type mut_;
|
||||
std::vector<double> data_;
|
||||
|
||||
public:
|
||||
|
||||
A(const A& a)
|
||||
{
|
||||
SharedLock _(a.mut_);
|
||||
data_ = a.data_;
|
||||
}
|
||||
|
||||
A& operator=(const A& a)
|
||||
{
|
||||
if (this != &a)
|
||||
{
|
||||
Lock this_lock(mut_, boost::defer_lock);
|
||||
SharedLock that_lock(a.mut_, boost::defer_lock);
|
||||
boost::lock(this_lock, that_lock);
|
||||
data_ = a.data_;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(A& a)
|
||||
{
|
||||
Lock this_lock(mut_, boost::defer_lock);
|
||||
Lock that_lock(a.mut_, boost::defer_lock);
|
||||
boost::lock(this_lock, that_lock);
|
||||
data_.swap(a.data_);
|
||||
}
|
||||
|
||||
void average(A& a)
|
||||
{
|
||||
assert(data_.size() == a.data_.size());
|
||||
assert(this != &a);
|
||||
|
||||
Lock this_lock(mut_, boost::defer_lock);
|
||||
UpgradeLock share_that_lock(a.mut_, boost::defer_lock);
|
||||
boost::lock(this_lock, share_that_lock);
|
||||
|
||||
for (unsigned i = 0; i < data_.size(); ++i)
|
||||
data_[i] = (data_[i] + a.data_[i]) / 2;
|
||||
|
||||
SharedLock share_this_lock(boost::move(this_lock));
|
||||
Lock that_lock(boost::move(share_that_lock));
|
||||
a.data_ = data_;
|
||||
}
|
||||
};
|
||||
|
||||
} // Assignment
|
||||
|
||||
void temp()
|
||||
{
|
||||
using namespace boost;
|
||||
static upgrade_mutex mut;
|
||||
unique_lock<upgrade_mutex> ul(mut);
|
||||
shared_lock<upgrade_mutex> sl;
|
||||
sl = BOOST_THREAD_MAKE_RV_REF(shared_lock<upgrade_mutex>(boost::move(ul)));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
typedef boost::chrono::high_resolution_clock Clock;
|
||||
typedef boost::chrono::duration<double> sec;
|
||||
Clock::time_point t0 = Clock::now();
|
||||
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
S::test_shared_mutex();
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
U::test_upgrade_mutex();
|
||||
std::cout << __FILE__ << "[" <<__LINE__ << "]" << std::endl;
|
||||
Clock::time_point t1 = Clock::now();
|
||||
std::cout << sec(t1 - t0) << '\n';
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
#error "This platform doesn't support Boost.Chrono"
|
||||
#endif
|
||||
@@ -1,12 +1,14 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_THREAD_VERSION 2
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/condition.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include <boost/thread/xtime.hpp>
|
||||
#include <iostream>
|
||||
#include <time.h>
|
||||
@@ -23,18 +25,18 @@ public:
|
||||
|
||||
void get(int id)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_mutex);
|
||||
boost::unique_lock<boost::mutex> lock(m_mutex);
|
||||
while (m_chickens == 0)
|
||||
{
|
||||
{
|
||||
boost::mutex::scoped_lock lock(iomx);
|
||||
boost::unique_lock<boost::mutex> lk(iomx);
|
||||
std::cout << "(" << clock() << ") Phil" << id <<
|
||||
": wot, no chickens? I'll WAIT ..." << std::endl;
|
||||
}
|
||||
m_condition.wait(lock);
|
||||
}
|
||||
{
|
||||
boost::mutex::scoped_lock lock(iomx);
|
||||
boost::unique_lock<boost::mutex> lk(iomx);
|
||||
std::cout << "(" << clock() << ") Phil" << id <<
|
||||
": those chickens look good ... one please ..." << std::endl;
|
||||
}
|
||||
@@ -42,20 +44,20 @@ public:
|
||||
}
|
||||
void put(int value)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_mutex);
|
||||
boost::unique_lock<boost::mutex> lock(m_mutex);
|
||||
{
|
||||
boost::mutex::scoped_lock lock(iomx);
|
||||
boost::unique_lock<boost::mutex> lk(iomx);
|
||||
std::cout << "(" << clock()
|
||||
<< ") Chef: ouch ... make room ... this dish is "
|
||||
<< "very hot ..." << std::endl;
|
||||
}
|
||||
boost::xtime xt;
|
||||
boost::xtime_get(&xt, boost::TIME_UTC);
|
||||
boost::xtime_get(&xt, boost::TIME_UTC_);
|
||||
xt.sec += 3;
|
||||
boost::thread::sleep(xt);
|
||||
m_chickens += value;
|
||||
{
|
||||
boost::mutex::scoped_lock lock(iomx);
|
||||
boost::unique_lock<boost::mutex> lk(iomx);
|
||||
std::cout << "(" << clock() <<
|
||||
") Chef: more chickens ... " << m_chickens <<
|
||||
" now available ... NOTIFYING ..." << std::endl;
|
||||
@@ -75,21 +77,21 @@ void chef()
|
||||
{
|
||||
const int chickens = 4;
|
||||
{
|
||||
boost::mutex::scoped_lock lock(iomx);
|
||||
boost::unique_lock<boost::mutex> lock(iomx);
|
||||
std::cout << "(" << clock() << ") Chef: starting ..." << std::endl;
|
||||
}
|
||||
for (;;)
|
||||
{
|
||||
{
|
||||
boost::mutex::scoped_lock lock(iomx);
|
||||
boost::unique_lock<boost::mutex> lock(iomx);
|
||||
std::cout << "(" << clock() << ") Chef: cooking ..." << std::endl;
|
||||
}
|
||||
boost::xtime xt;
|
||||
boost::xtime_get(&xt, boost::TIME_UTC);
|
||||
boost::xtime_get(&xt, boost::TIME_UTC_);
|
||||
xt.sec += 2;
|
||||
boost::thread::sleep(xt);
|
||||
{
|
||||
boost::mutex::scoped_lock lock(iomx);
|
||||
boost::unique_lock<boost::mutex> lock(iomx);
|
||||
std::cout << "(" << clock() << ") Chef: " << chickens
|
||||
<< " chickens, ready-to-go ..." << std::endl;
|
||||
}
|
||||
@@ -102,7 +104,7 @@ struct phil
|
||||
phil(int id) : m_id(id) { }
|
||||
void run() {
|
||||
{
|
||||
boost::mutex::scoped_lock lock(iomx);
|
||||
boost::unique_lock<boost::mutex> lock(iomx);
|
||||
std::cout << "(" << clock() << ") Phil" << m_id
|
||||
<< ": starting ..." << std::endl;
|
||||
}
|
||||
@@ -111,18 +113,18 @@ struct phil
|
||||
if (m_id > 0)
|
||||
{
|
||||
boost::xtime xt;
|
||||
boost::xtime_get(&xt, boost::TIME_UTC);
|
||||
boost::xtime_get(&xt, boost::TIME_UTC_);
|
||||
xt.sec += 3;
|
||||
boost::thread::sleep(xt);
|
||||
}
|
||||
{
|
||||
boost::mutex::scoped_lock lock(iomx);
|
||||
boost::unique_lock<boost::mutex> lk(iomx);
|
||||
std::cout << "(" << clock() << ") Phil" << m_id
|
||||
<< ": gotta eat ..." << std::endl;
|
||||
}
|
||||
g_canteen.get(m_id);
|
||||
{
|
||||
boost::mutex::scoped_lock lock(iomx);
|
||||
boost::unique_lock<boost::mutex> lk(iomx);
|
||||
std::cout << "(" << clock() << ") Phil" << m_id
|
||||
<< ": mmm ... that's good ..." << std::endl;
|
||||
}
|
||||
@@ -164,7 +166,7 @@ private:
|
||||
void* _param;
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main()
|
||||
{
|
||||
boost::thread thrd_chef(&chef);
|
||||
phil p[] = { phil(0), phil(1), phil(2), phil(3), phil(4) };
|
||||
|
||||
40
example/strict_lock.cpp
Normal file
40
example/strict_lock.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2012 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/lock_traits.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/thread/strict_lock.hpp>
|
||||
#include <boost/thread/lock_types.hpp>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
BOOST_STATIC_ASSERT(boost::is_strict_lock<boost::strict_lock<boost::mutex> >::value);
|
||||
BOOST_CONCEPT_ASSERT(( boost::BasicLockable<boost::mutex> ));
|
||||
BOOST_CONCEPT_ASSERT(( boost::StrictLock<boost::strict_lock<boost::mutex> > ));
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::mutex mtx;
|
||||
boost::strict_lock<boost::mutex> lk(mtx);
|
||||
std::cout << __FILE__ << std::endl;
|
||||
}
|
||||
{
|
||||
boost::timed_mutex mtx;
|
||||
boost::unique_lock<boost::timed_mutex> lk(mtx);
|
||||
boost::nested_strict_lock<boost::unique_lock<boost::timed_mutex> > nlk(lk);
|
||||
std::cout << __FILE__ << std::endl;
|
||||
}
|
||||
{
|
||||
boost::mutex mtx;
|
||||
boost::unique_lock<boost::mutex> lk(mtx, boost::defer_lock);
|
||||
boost::nested_strict_lock<boost::unique_lock<boost::mutex> > nlk(lk);
|
||||
std::cout << __FILE__ << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
282
example/synchronized_person.cpp
Normal file
282
example/synchronized_person.cpp
Normal file
@@ -0,0 +1,282 @@
|
||||
// (C) Copyright 2012 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <boost/thread/synchronized_value.hpp>
|
||||
|
||||
//class SafePerson {
|
||||
//public:
|
||||
// std::string GetName() const {
|
||||
// const_unique_access<std::string> name(nameGuard);
|
||||
// return *name;
|
||||
// }
|
||||
// void SetName(const std::string& newName) {
|
||||
// unique_access<std::string> name(nameGuard);
|
||||
// *name = newName;
|
||||
// }
|
||||
//private:
|
||||
// unique_access_guard<std::string> nameGuard;
|
||||
//};
|
||||
|
||||
class SafePerson {
|
||||
public:
|
||||
std::string GetName() const {
|
||||
return *name;
|
||||
}
|
||||
void SetName(const std::string& newName) {
|
||||
*name = newName;
|
||||
}
|
||||
|
||||
private:
|
||||
boost::synchronized_value<std::string> name;
|
||||
};
|
||||
|
||||
class Person {
|
||||
public:
|
||||
std::string GetName() const {
|
||||
return name;
|
||||
}
|
||||
void SetName(const std::string& newName) {
|
||||
name = newName;
|
||||
}
|
||||
private:
|
||||
std::string name;
|
||||
};
|
||||
typedef boost::synchronized_value<Person> Person_ts;
|
||||
|
||||
|
||||
//class SafeMemberPerson {
|
||||
//public:
|
||||
// SafeMemberPerson(unsigned int age) :
|
||||
// memberGuard(age)
|
||||
// { }
|
||||
// std::string GetName() const {
|
||||
// const_unique_access<Member> member(memberGuard);
|
||||
// return member->name;
|
||||
// }
|
||||
// void SetName(const std::string& newName) {
|
||||
// unique_access<Member> member(memberGuard);
|
||||
// member->name = newName;
|
||||
// }
|
||||
//private:
|
||||
// struct Member
|
||||
// {
|
||||
// Member(unsigned int age) :
|
||||
// age(age)
|
||||
// { }
|
||||
// std::string name;
|
||||
// unsigned int age;
|
||||
// };
|
||||
// unique_access_guard<Member> memberGuard;
|
||||
//};
|
||||
|
||||
class SafeMemberPerson {
|
||||
public:
|
||||
SafeMemberPerson(unsigned int age) :
|
||||
member(Member(age))
|
||||
{ }
|
||||
std::string GetName() const {
|
||||
return member->name;
|
||||
}
|
||||
void SetName(const std::string& newName) {
|
||||
member->name = newName;
|
||||
}
|
||||
private:
|
||||
struct Member {
|
||||
Member(unsigned int age) :
|
||||
age(age)
|
||||
{ }
|
||||
std::string name;
|
||||
unsigned int age;
|
||||
};
|
||||
boost::synchronized_value<Member> member;
|
||||
};
|
||||
|
||||
|
||||
class Person2 {
|
||||
public:
|
||||
Person2(unsigned int age) : age_(age)
|
||||
{}
|
||||
std::string GetName() const {
|
||||
return name_;
|
||||
}
|
||||
void SetName(const std::string& newName) {
|
||||
name_ = newName;
|
||||
}
|
||||
unsigned int GetAge() const {
|
||||
return age_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
unsigned int age_;
|
||||
};
|
||||
typedef boost::synchronized_value<Person2> Person2_ts;
|
||||
|
||||
//===================
|
||||
|
||||
//class HelperPerson {
|
||||
//public:
|
||||
// HelperPerson(unsigned int age) :
|
||||
// memberGuard(age)
|
||||
// { }
|
||||
// std::string GetName() const {
|
||||
// const_unique_access<Member> member(memberGuard);
|
||||
// Invariant(member);
|
||||
// return member->name;
|
||||
// }
|
||||
// void SetName(const std::string& newName) {
|
||||
// unique_access<Member> member(memberGuard);
|
||||
// Invariant(member);
|
||||
// member->name = newName;
|
||||
// }
|
||||
//private:
|
||||
// void Invariant(const_unique_access<Member>& member) const {
|
||||
// if (member->age < 0) throw std::runtime_error("Age cannot be negative");
|
||||
// }
|
||||
// struct Member {
|
||||
// Member(unsigned int age) :
|
||||
// age(age)
|
||||
// { }
|
||||
// std::string name;
|
||||
// unsigned int age;
|
||||
// };
|
||||
// unique_access_guard<Member> memberGuard;
|
||||
//};
|
||||
|
||||
class HelperPerson {
|
||||
public:
|
||||
HelperPerson(unsigned int age) :
|
||||
member(age)
|
||||
{ }
|
||||
std::string GetName() const {
|
||||
#if ! defined BOOST_NO_CXX11_AUTO_DECLARATIONS
|
||||
auto memberSync = member.synchronize();
|
||||
#else
|
||||
boost::const_strict_lock_ptr<Member> memberSync = member.synchronize();
|
||||
#endif
|
||||
Invariant(memberSync);
|
||||
return memberSync->name;
|
||||
}
|
||||
void SetName(const std::string& newName) {
|
||||
#if ! defined BOOST_NO_CXX11_AUTO_DECLARATIONS
|
||||
auto memberSync = member.synchronize();
|
||||
#else
|
||||
boost::strict_lock_ptr<Member> memberSync = member.synchronize();
|
||||
#endif
|
||||
Invariant(memberSync);
|
||||
memberSync->name = newName;
|
||||
}
|
||||
private:
|
||||
struct Member {
|
||||
Member(unsigned int age) :
|
||||
age(age)
|
||||
{ }
|
||||
std::string name;
|
||||
unsigned int age;
|
||||
};
|
||||
void Invariant(boost::const_strict_lock_ptr<Member> & mbr) const
|
||||
{
|
||||
if (mbr->age < 1) throw std::runtime_error("Age cannot be negative");
|
||||
}
|
||||
boost::synchronized_value<Member> member;
|
||||
};
|
||||
|
||||
class Person3 {
|
||||
public:
|
||||
Person3(unsigned int age) :
|
||||
age_(age)
|
||||
{ }
|
||||
std::string GetName() const {
|
||||
Invariant();
|
||||
return name_;
|
||||
}
|
||||
void SetName(const std::string& newName) {
|
||||
Invariant();
|
||||
name_ = newName;
|
||||
}
|
||||
private:
|
||||
std::string name_;
|
||||
unsigned int age_;
|
||||
void Invariant() const {
|
||||
if (age_ < 1) throw std::runtime_error("Age cannot be negative");
|
||||
}
|
||||
};
|
||||
|
||||
typedef boost::synchronized_value<Person3> Person3_ts;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
SafePerson p;
|
||||
p.SetName("Vicente");
|
||||
}
|
||||
{
|
||||
Person_ts p;
|
||||
p->SetName("Vicente");
|
||||
}
|
||||
{
|
||||
SafeMemberPerson p(1);
|
||||
p.SetName("Vicente");
|
||||
}
|
||||
{
|
||||
Person2_ts p(1);
|
||||
p->SetName("Vicente");
|
||||
}
|
||||
{
|
||||
HelperPerson p(1);
|
||||
p.SetName("Vicente");
|
||||
}
|
||||
{
|
||||
Person3_ts p(1);
|
||||
p->SetName("Vicente");
|
||||
}
|
||||
{
|
||||
Person3_ts p1(1);
|
||||
Person3_ts p2(2);
|
||||
Person3_ts p3(3);
|
||||
#if ! defined BOOST_NO_CXX11_AUTO_DECLARATIONS
|
||||
auto lk1 = p1.unique_synchronize(boost::defer_lock);
|
||||
auto lk2 = p2.unique_synchronize(boost::defer_lock);
|
||||
auto lk3 = p3.unique_synchronize(boost::defer_lock);
|
||||
#else
|
||||
boost::unique_lock_ptr<Person3> lk1 = p1.unique_synchronize(boost::defer_lock);
|
||||
boost::unique_lock_ptr<Person3> lk2 = p2.unique_synchronize(boost::defer_lock);
|
||||
boost::unique_lock_ptr<Person3> lk3 = p3.unique_synchronize(boost::defer_lock);
|
||||
#endif
|
||||
boost::lock(lk1,lk2,lk3);
|
||||
|
||||
lk1->SetName("Carmen");
|
||||
lk2->SetName("Javier");
|
||||
lk3->SetName("Matias");
|
||||
}
|
||||
#if ! defined BOOST_NO_CXX11_AUTO_DECLARATIONS \
|
||||
&& ! defined(BOOST_THREAD_NO_SYNCHRONIZE)
|
||||
{
|
||||
Person3_ts p1(1);
|
||||
Person3_ts p2(2);
|
||||
Person3_ts p3(3);
|
||||
|
||||
auto t = boost::synchronize(p1,p2,p3);
|
||||
std::get<0>(t)->SetName("Carmen");
|
||||
std::get<1>(t)->SetName("Javier");
|
||||
std::get<2>(t)->SetName("Matias");
|
||||
}
|
||||
{
|
||||
const Person3_ts p1(1);
|
||||
Person3_ts p2(2);
|
||||
const Person3_ts p3(3);
|
||||
|
||||
auto t = boost::synchronize(p1,p2,p3);
|
||||
//std::get<0>(t)->SetName("Carmen");
|
||||
std::get<1>(t)->SetName("Javier");
|
||||
//std::get<2>(t)->SetName("Matias");
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
147
example/synchronized_value.cpp
Normal file
147
example/synchronized_value.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
// (C) Copyright 2010 Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk
|
||||
// (C) Copyright 2012 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <boost/thread/synchronized_value.hpp>
|
||||
|
||||
void addTrailingSlashIfMissing(boost::synchronized_value<std::string> & path)
|
||||
{
|
||||
boost::strict_lock_ptr<std::string> u=path.synchronize();
|
||||
|
||||
if(u->empty() || (*u->rbegin()!='/'))
|
||||
{
|
||||
*u+='/';
|
||||
}
|
||||
}
|
||||
|
||||
void f(const boost::synchronized_value<int> &v) {
|
||||
std::cout<<"v="<<*v<<std::endl;
|
||||
}
|
||||
|
||||
void g(const boost::const_strict_lock_ptr<int> &v) {
|
||||
std::cout<<"v="<<*v<<std::endl;
|
||||
}
|
||||
|
||||
bool checkIfMissingTrailingSlash(boost::synchronized_value<std::string> & path)
|
||||
{
|
||||
boost::strict_lock_ptr<std::string> u=path.synchronize();
|
||||
|
||||
return (u->empty() || (*u->rbegin()!='/'));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::synchronized_value<int> v1;
|
||||
*v1=42;
|
||||
std::cout<<"v1="<<*v1<<std::endl;
|
||||
f(v1);
|
||||
int i=*v1;
|
||||
std::cout<<"i="<<i<<std::endl;
|
||||
|
||||
{
|
||||
boost::strict_lock_ptr<int> u=v1.synchronize();
|
||||
|
||||
*u+=43;
|
||||
std::cout<<"v1="<<*u<<std::endl;
|
||||
g(u);
|
||||
}
|
||||
boost::synchronized_value<int> v2(2);
|
||||
std::cout<<"v2="<<*v2<<std::endl;
|
||||
v2 = 3;
|
||||
std::cout<<"v2="<<*v2<<std::endl;
|
||||
|
||||
boost::synchronized_value<int> v3(v2);
|
||||
std::cout<<"v3="<<*v3<<std::endl;
|
||||
v3 = v1;
|
||||
std::cout<<"v3="<<*v3<<std::endl;
|
||||
|
||||
std::cout<<"v2="<<*v3<<std::endl;
|
||||
std::cout<<"v3="<<*v3<<std::endl;
|
||||
swap(v3,v2);
|
||||
v1.swap(v2);
|
||||
std::cout<<"v3="<<*v3<<std::endl;
|
||||
}
|
||||
{
|
||||
boost::synchronized_value<std::string> s;
|
||||
addTrailingSlashIfMissing(s);
|
||||
std::cout<<"s="<<std::string(*s)<<std::endl;
|
||||
}
|
||||
{
|
||||
boost::synchronized_value<std::string> s;
|
||||
s->append("foo/");
|
||||
s.synchronize()->append("foo");
|
||||
addTrailingSlashIfMissing(s);
|
||||
std::cout<<"s="<<std::string(*s)<<std::endl;
|
||||
}
|
||||
{
|
||||
boost::synchronized_value<std::string> s;
|
||||
s = std::string("foo/");
|
||||
std::cout<<"ss="<< s << std::endl;
|
||||
}
|
||||
{
|
||||
boost::synchronized_value<std::string> s;
|
||||
s = "foo/";
|
||||
std::cout<<"ss="<< s << std::endl;
|
||||
}
|
||||
{
|
||||
boost::synchronized_value<std::string> s1("a");
|
||||
boost::synchronized_value<std::string> s2;
|
||||
s2=s1;
|
||||
std::cout<<"s1="<< s1 << std::endl;
|
||||
std::cout<<"s2="<< s2 << std::endl;
|
||||
}
|
||||
{
|
||||
boost::synchronized_value<std::string> s1("a");
|
||||
boost::synchronized_value<std::string> s2("b");
|
||||
std::cout<<"s1="<< s1 << std::endl;
|
||||
std::cout<<"s2="<< s2 << std::endl;
|
||||
swap(s1,s2);
|
||||
std::cout<<"s1="<< s1 << std::endl;
|
||||
std::cout<<"s2="<< s2 << std::endl;
|
||||
}
|
||||
#if ! defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
|
||||
{
|
||||
boost::synchronized_value<std::string> sts("a");
|
||||
std::string s(sts);
|
||||
std::cout<<"ssts="<< s << std::endl;
|
||||
}
|
||||
#endif
|
||||
{
|
||||
boost::synchronized_value<int> s1(1);
|
||||
boost::synchronized_value<int> s2(1);
|
||||
BOOST_ASSERT(s1==s2);
|
||||
BOOST_ASSERT(s1<=s2);
|
||||
BOOST_ASSERT(s1>=s2);
|
||||
BOOST_ASSERT(s1==1);
|
||||
BOOST_ASSERT(s1<=1);
|
||||
BOOST_ASSERT(s1>=1);
|
||||
}
|
||||
{
|
||||
boost::synchronized_value<int> s1(1);
|
||||
boost::synchronized_value<int> s2(2);
|
||||
BOOST_ASSERT(s1!=s2);
|
||||
BOOST_ASSERT(s1!=2);
|
||||
BOOST_ASSERT(2!=s1);
|
||||
}
|
||||
{
|
||||
boost::synchronized_value<int> s1(1);
|
||||
boost::synchronized_value<int> s2(2);
|
||||
BOOST_ASSERT(s1<s2);
|
||||
BOOST_ASSERT(s1<=s2);
|
||||
BOOST_ASSERT(s2>s1);
|
||||
BOOST_ASSERT(s2>=s1);
|
||||
BOOST_ASSERT(s1<2);
|
||||
BOOST_ASSERT(s1<=2);
|
||||
BOOST_ASSERT(s2>1);
|
||||
BOOST_ASSERT(s2>=1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#undef BOOST_THREAD_VERSION
|
||||
#define BOOST_THREAD_VERSION 2
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/condition.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include <boost/thread/xtime.hpp>
|
||||
#include <iostream>
|
||||
|
||||
@@ -29,7 +32,7 @@ int state;
|
||||
boost::mutex mutex;
|
||||
boost::condition cond;
|
||||
|
||||
char* player_name(int state)
|
||||
const char* player_name(int state)
|
||||
{
|
||||
if (state == PLAYER_A)
|
||||
return "PLAYER-A";
|
||||
@@ -39,11 +42,10 @@ char* player_name(int state)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void player(void* param)
|
||||
void player(int active)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(mutex);
|
||||
boost::unique_lock<boost::mutex> lock(mutex);
|
||||
|
||||
int active = (int)param;
|
||||
int other = active == PLAYER_A ? PLAYER_B : PLAYER_A;
|
||||
|
||||
while (state < GAME_OVER)
|
||||
@@ -96,27 +98,27 @@ private:
|
||||
void* _param;
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main()
|
||||
{
|
||||
state = START;
|
||||
|
||||
boost::thread thrda(thread_adapter(&player, (void*)PLAYER_A));
|
||||
boost::thread thrdb(thread_adapter(&player, (void*)PLAYER_B));
|
||||
boost::thread thrda(&player, PLAYER_A);
|
||||
boost::thread thrdb(&player, PLAYER_B);
|
||||
|
||||
boost::xtime xt;
|
||||
boost::xtime_get(&xt, boost::TIME_UTC);
|
||||
boost::xtime_get(&xt, boost::TIME_UTC_);
|
||||
xt.sec += 1;
|
||||
boost::thread::sleep(xt);
|
||||
{
|
||||
boost::mutex::scoped_lock lock(mutex);
|
||||
boost::unique_lock<boost::mutex> lock(mutex);
|
||||
std::cout << "---Noise ON..." << std::endl;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1000000; ++i)
|
||||
for (int i = 0; i < 10; ++i)
|
||||
cond.notify_all();
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock lock(mutex);
|
||||
boost::unique_lock<boost::mutex> lock(mutex);
|
||||
std::cout << "---Noise OFF..." << std::endl;
|
||||
state = GAME_OVER;
|
||||
cond.notify_all();
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
#define BOOST_THREAD_VERSION 2
|
||||
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include <boost/thread/xtime.hpp>
|
||||
#include <iostream>
|
||||
|
||||
@@ -14,7 +16,7 @@ struct thread_alarm
|
||||
void operator()()
|
||||
{
|
||||
boost::xtime xt;
|
||||
boost::xtime_get(&xt, boost::TIME_UTC);
|
||||
boost::xtime_get(&xt, boost::TIME_UTC_);
|
||||
xt.sec += m_secs;
|
||||
|
||||
boost::thread::sleep(xt);
|
||||
@@ -25,7 +27,7 @@ struct thread_alarm
|
||||
int m_secs;
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main()
|
||||
{
|
||||
int secs = 5;
|
||||
std::cout << "setting alarm for 5 seconds..." << std::endl;
|
||||
|
||||
@@ -1,25 +1,72 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <iostream>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int count = 0;
|
||||
boost::mutex mutex;
|
||||
|
||||
void increment_count()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(mutex);
|
||||
boost::unique_lock<boost::mutex> lock(mutex);
|
||||
std::cout << "count = " << ++count << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
boost::thread_group threads2;
|
||||
boost::thread* th2 = 0;
|
||||
|
||||
void increment_count_2()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lock(mutex);
|
||||
BOOST_TEST(threads2.is_this_thread_in());
|
||||
std::cout << "count = " << ++count << std::endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::thread_group threads;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
for (int i = 0; i < 3; ++i)
|
||||
threads.create_thread(&increment_count);
|
||||
threads.join_all();
|
||||
}
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
{
|
||||
boost::thread_group threads;
|
||||
for (int i = 0; i < 3; ++i)
|
||||
threads.create_thread(&increment_count);
|
||||
threads.interrupt_all();
|
||||
threads.join_all();
|
||||
}
|
||||
#endif
|
||||
{
|
||||
boost::thread_group threads;
|
||||
boost::thread* th = new boost::thread(&increment_count);
|
||||
threads.add_thread(th);
|
||||
BOOST_TEST(! threads.is_this_thread_in());
|
||||
threads.join_all();
|
||||
}
|
||||
{
|
||||
boost::thread_group threads;
|
||||
boost::thread* th = new boost::thread(&increment_count);
|
||||
threads.add_thread(th);
|
||||
BOOST_TEST(threads.is_thread_in(th));
|
||||
threads.remove_thread(th);
|
||||
BOOST_TEST(! threads.is_thread_in(th));
|
||||
th->join();
|
||||
}
|
||||
{
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lock(mutex);
|
||||
boost::thread* th2 = new boost::thread(&increment_count_2);
|
||||
threads2.add_thread(th2);
|
||||
}
|
||||
threads2.join_all();
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
57
example/thread_guard.cpp
Normal file
57
example/thread_guard.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
// (C) Copyright 2009-2012 Anthony Williams
|
||||
// (C) Copyright 2012 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include <boost/thread/thread_guard.hpp>
|
||||
|
||||
void do_something(int& i)
|
||||
{
|
||||
++i;
|
||||
}
|
||||
|
||||
struct func
|
||||
{
|
||||
int& i;
|
||||
|
||||
func(int& i_):i(i_){}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
for(unsigned j=0;j<1000000;++j)
|
||||
{
|
||||
do_something(i);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
func& operator=(func const&);
|
||||
|
||||
};
|
||||
|
||||
void do_something_in_current_thread()
|
||||
{}
|
||||
|
||||
|
||||
void f()
|
||||
{
|
||||
int some_local_state;
|
||||
func my_func(some_local_state);
|
||||
boost::thread t(my_func);
|
||||
boost::thread_guard<> g(t);
|
||||
|
||||
do_something_in_current_thread();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
f();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
73
example/thread_pool.cpp
Normal file
73
example/thread_pool.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright (C) 2012-2013 Vicente Botet
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
//#define BOOST_THREAD_USES_LOG
|
||||
#define BOOST_THREAD_USES_LOG_THREAD_ID
|
||||
#define BOOST_THREAD_QUEUE_DEPRECATE_OLD
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
|
||||
#include <boost/thread/detail/log.hpp>
|
||||
#include <boost/thread/executors/basic_thread_pool.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <string>
|
||||
|
||||
void p1()
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << " P1" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
|
||||
void p2()
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << " P2" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
|
||||
void submit_some(boost::basic_thread_pool& tp) {
|
||||
tp.submit(&p1);
|
||||
tp.submit(&p2);
|
||||
tp.submit(&p1);
|
||||
tp.submit(&p2);
|
||||
tp.submit(&p1);
|
||||
tp.submit(&p2);
|
||||
tp.submit(&p1);
|
||||
tp.submit(&p2);
|
||||
tp.submit(&p1);
|
||||
tp.submit(&p2);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << " <MAIN" << BOOST_THREAD_END_LOG;
|
||||
{
|
||||
try
|
||||
{
|
||||
boost::basic_thread_pool tp;
|
||||
submit_some(tp);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< "ERRORRRRR " << ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << "MAIN>" << BOOST_THREAD_END_LOG;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
@@ -27,7 +27,7 @@ void thread_proc()
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main()
|
||||
{
|
||||
boost::thread_group threads;
|
||||
for (int i=0; i<5; ++i)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user