File tree 6 files changed +77
-0
lines changed
6 files changed +77
-0
lines changed Original file line number Diff line number Diff line change
1
+ sample [0-9 ][0-9 ]
2
+ counting
Original file line number Diff line number Diff line change
1
+ PROGRAMS = sample01 sample02 sample03 counting
2
+
3
+ all : $(PROGRAMS )
4
+
5
+ ALLPROGRAMS = $(PROGRAMS )
6
+ CONFIGMK ?= config.mk
7
+
8
+ O ?= 3
9
+ PTHREAD ?= 1
10
+ include ../common/rules.mk
11
+ -include $(CONFIGMK )
12
+
13
+ % .o : % .cc $(BUILDSTAMP )
14
+ $(CXX ) $(CPPFLAGS ) $(CXXFLAGS ) $(DEPCFLAGS ) $(O ) -o $@ -c $<
15
+
16
+ $(PROGRAMS ) : \
17
+ % : % .o
18
+ $(CXX ) $(CXXFLAGS ) $(O ) $(LDFLAGS ) -o $@ $^ $(LIBS )
19
+
20
+
21
+ clean :
22
+ rm -f $(ALLPROGRAMS ) * .o
23
+ rm -rf $(DEPSDIR ) * .dSYM
24
+
25
+ .PHONY : all always clean
Original file line number Diff line number Diff line change
1
+ #include < cstdio>
2
+ #include < cassert>
3
+ #include < thread>
4
+ #include < mutex>
5
+ #include < condition_variable>
6
+
7
+ /* G1 */
8
+
9
+ void counter (int n) {
10
+ /* C1 */
11
+ printf (" %d\n " , n + 1 );
12
+ /* C2 */
13
+ }
14
+
15
+ int main () {
16
+ /* M1 */
17
+ std::thread t1 (counter, 0 );
18
+ std::thread t2 (counter, 1 );
19
+ std::thread t3 (counter, 2 );
20
+ /* M2 */
21
+ t3.join ();
22
+ t2.join ();
23
+ t1.join ();
24
+ }
Original file line number Diff line number Diff line change
1
+ #include < cstdio>
2
+ #include < thread>
3
+
4
+ int main () {
5
+ for (int i = 0 ; i != 3 ; ++i) {
6
+ std::thread t (printf , " %d\n " , i + 1 );
7
+ t.join ();
8
+ }
9
+ }
Original file line number Diff line number Diff line change
1
+ #include < cstdio>
2
+ #include < thread>
3
+
4
+ int main () {
5
+ for (int i = 0 ; i != 3 ; ++i) {
6
+ std::thread t (printf , " %d\n " , i + 1 );
7
+ t.detach ();
8
+ }
9
+ }
Original file line number Diff line number Diff line change
1
+ #include < cstdio>
2
+ #include < thread>
3
+
4
+ int main () {
5
+ for (int i = 0 ; i != 3 ; ++i) {
6
+ std::thread t (printf , " %d\n " , i + 1 );
7
+ }
8
+ }
You can’t perform that action at this time.
0 commit comments