* Starts the thread. Does platform specific thread creation and * configuration then invokes the run method of the Runnable object bound * to this thread. */
| 119 | * to this thread. |
| 120 | */ |
| 121 | virtual void start() { |
| 122 | if (getState() != uninitialized) { |
| 123 | return; |
| 124 | } |
| 125 | |
| 126 | std::shared_ptr<Thread> selfRef = shared_from_this(); |
| 127 | setState(starting); |
| 128 | |
| 129 | Synchronized sync(monitor_); |
| 130 | thread_ = std::unique_ptr<std::thread>(new std::thread(getThreadFunc(), selfRef)); |
| 131 | |
| 132 | if (detached_) |
| 133 | thread_->detach(); |
| 134 | |
| 135 | // Wait for the thread to start and get far enough to grab everything |
| 136 | // that it needs from the calling context, thus absolving the caller |
| 137 | // from being required to hold on to runnable indefinitely. |
| 138 | monitor_.wait(); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Join this thread. If this thread is joinable, the calling thread blocks |