diff --git a/pink/examples/bg_thread.cc b/pink/examples/bg_thread.cc index 905aa2e4..4bb7af24 100644 --- a/pink/examples/bg_thread.cc +++ b/pink/examples/bg_thread.cc @@ -56,6 +56,7 @@ int main() { sleep(1); } + qsize = pqsize = 0; std::cout << "Limit queue BGTask... " << std::endl; for (int i = 0; i < 10; i++) { @@ -86,6 +87,9 @@ int main() { } std::cout << std::endl << std::endl; + std::cout << "Restart BGThread" << std::endl; + t.StopThread(); + t.StartThread(); std::cout << "Time BGTask... " << std::endl; for (int i = 0; i < 10; i++) { int *pi = new int(i); diff --git a/pink/src/pink_thread.cc b/pink/src/pink_thread.cc index 71a7d135..847b6f3e 100644 --- a/pink/src/pink_thread.cc +++ b/pink/src/pink_thread.cc @@ -30,6 +30,7 @@ void* Thread::RunThread(void *arg) { int Thread::StartThread() { slash::MutexLock l(&running_mu_); + should_stop_ = false; if (!running_) { running_ = true; return pthread_create(&thread_id_, nullptr, RunThread, (void *)this); @@ -38,8 +39,8 @@ int Thread::StartThread() { } int Thread::StopThread() { - should_stop_ = true; slash::MutexLock l(&running_mu_); + should_stop_ = true; if (running_) { running_ = false; return pthread_join(thread_id_, nullptr);