File: thread.cpp

package info (click to toggle)
yrmcds 1.0.4-6
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 924 kB
  • ctags: 1,346
  • sloc: cpp: 9,634; sh: 133; makefile: 97
file content (35 lines) | stat: -rw-r--r-- 632 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <cybozu/thread.hpp>

#include <iostream>
#include <mutex>
#include <memory>
#include <stdexcept>
#include <thread>

struct ttt: public cybozu::thread_base<ttt, 0> {
    ttt(): cybozu::thread_base<ttt, 0>() {}
    int i = 3;

    void run() {
        std::cout << "i = " << i << std::endl;
        throw std::runtime_error("hoge");
    }

    void stop() {
        m_thread.join();
    }
};

int main() {
    std::unique_ptr<int> p;
    std::once_flag f;
    std::call_once(f, [&]{
            p.reset(new int);
        });
    std::cout << "*p=" << *p << std::endl;

    ttt t;
    t.start();
    t.stop();
    return 0;
}