mirror of
https://github.com/sogou/workflow.git
synced 2026-02-08 01:33:17 +08:00
pause() replace by WaitGroup
This commit is contained in:
@@ -18,17 +18,15 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include "workflow/WFTaskFactory.h"
|
||||
|
||||
bool use_parallel_sort = false;
|
||||
bool finished = false;
|
||||
std::mutex mutex;
|
||||
std::condition_variable cond;
|
||||
#include "workflow/WFFacilities.h"
|
||||
|
||||
using namespace algorithm;
|
||||
|
||||
static WFFacilities::WaitGroup wait_group(1);
|
||||
|
||||
bool use_parallel_sort = false;
|
||||
|
||||
void callback(WFSortTask<int> *task)
|
||||
{
|
||||
/* Sort task's input and output are identical. */
|
||||
@@ -60,12 +58,7 @@ void callback(WFSortTask<int> *task)
|
||||
printf("Sort reversely:\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
mutex.lock();
|
||||
finished = true;
|
||||
cond.notify_one();
|
||||
mutex.unlock();
|
||||
}
|
||||
wait_group.done();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -112,11 +105,7 @@ int main(int argc, char *argv[])
|
||||
printf("Sort result:\n");
|
||||
task->start();
|
||||
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
while (!finished)
|
||||
cond.wait(lock);
|
||||
lock.unlock();
|
||||
|
||||
wait_group.wait();
|
||||
free(array);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user