Skip to content

Commit

Permalink
fix Thread Restart failed problem
Browse files Browse the repository at this point in the history
  • Loading branch information
CatKang committed Sep 13, 2017
1 parent 13ecea4 commit a7ad25e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pink/examples/bg_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion pink/src/pink_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit a7ad25e

Please sign in to comment.