Skip to content

Commit 8f39b7a

Browse files
authored
Merge pull request #321 from openzim/fix_thread_termination
2 parents fb36ffd + bffcc42 commit 8f39b7a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/writer/creator.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ namespace zim
8989
{
9090
pthread_t thread;
9191
pthread_create(&thread, NULL, taskRunner, this->data.get());
92-
pthread_detach(thread);
92+
data->runningWriters.push_back(thread);
9393
}
9494

9595
pthread_create(&data->writerThread, NULL, clusterWriter, this->data.get());
@@ -199,6 +199,10 @@ namespace zim
199199
data->taskList.pushToQueue(nullptr);
200200
}
201201

202+
for(auto& thread: data->runningWriters) {
203+
pthread_join(thread, nullptr);
204+
}
205+
202206
// Be sure that all cluster are closed
203207
// Wait for writerThread to finish.
204208
data->clusterToWrite.pushToQueue(nullptr);

src/writer/creatordata.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ namespace zim
6666
typedef std::vector<Cluster*> ClusterList;
6767
typedef Queue<Cluster*> ClusterQueue;
6868
typedef Queue<Task*> TaskQueue;
69+
typedef std::vector<pthread_t> ThreadList;
6970

7071
CreatorData(const std::string& fname, bool verbose,
7172
bool withIndex, std::string language);
@@ -99,6 +100,7 @@ namespace zim
99100
ClusterList clustersList;
100101
ClusterQueue clusterToWrite;
101102
TaskQueue taskList;
103+
ThreadList runningWriters;
102104
pthread_t writerThread;
103105
CompressionType compression = zimcompLzma;
104106
std::string basename;

0 commit comments

Comments
 (0)