Example #1
0
    bool Thread::StartWithOptions(const Options& options)
    {
        DCHECK(!message_loop_);

        SetThreadWasQuitProperly(false);

        StartupData startup_data(options);
        startup_data_ = &startup_data;

        if(!Create(options.stack_size, this, &thread_))
        {
            DLOG(ERROR) << "failed to create thread";
            startup_data_ = NULL;
            return false;
        }

        // 等待线程启动并初始化message_loop_.
        startup_data.event.Wait();

        // 设置成NULL, 所以我们不会保存一个栈上对象的指针.
        startup_data_ = NULL;
        started_ = true;

        DCHECK(message_loop_);
        return true;
    }
Example #2
0
	bool Thread::StartWithOptions(const Options &options) {
		StartupData startup_data(options);
		startup_data_ = &startup_data;
		if (!ThreadHelper::Create(MakeRunnableMethod(this, &Thread::ThreadMain), &thread_handle_)) {
			assert(false);
			// TODO(tangjie): add log for create thread failed!
			startup_data_ = nullptr;
			return false;
		}
		startup_data.event_.Wait();
		startup_data_ = nullptr;
		was_started_ = true;
		assert(message_loop_ != false);
		return true;
	}