Skip to content

Commit 98e3c21

Browse files
added better cleanup
1 parent 89b05a2 commit 98e3c21

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

source/include/threadPool.hh

+2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
#include <condition_variable>
66
#include <cstddef>
77
#include <functional>
8+
#include <iostream>
89
#include <mutex>
910
#include <queue>
1011
#include <thread>
1112
#include <vector>
1213

14+
1315
class ThreadPool {
1416
public:
1517
ThreadPool(size_t threadCount);

source/src/efficientFinder.cc

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ int processFile(const fs::path &filePath, ThreadPool &pool) {
3535
return 0;
3636
}
3737

38+
ThreadPool *globalPool = nullptr;
39+
40+
// void cleanup() {
41+
// if (globalPool) {
42+
// globalPool->stopPool();
43+
// std::cout << "thread cleared";
44+
// }
45+
// }
46+
3847
int main() {
3948
std::string root;
4049

@@ -48,6 +57,8 @@ int main() {
4857
#endif
4958

5059
ThreadPool pool(std::thread::hardware_concurrency());
60+
globalPool = &pool; // Store reference to pool
61+
// std::atexit(cleanup); // Register cleanup() function
5162

5263
fs::recursive_directory_iterator it(root, fs::directory_options::skip_permission_denied), end;
5364
while (it != end) {

source/src/find.cc

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ bool checker(std::string inputfile) {
8282
std::cout << "LLLLLLLLOOOOOOOOWWWWWW T A P E R F A D E\n";
8383
wordMap["low"] = wordMap["taper"] = wordMap["fade"] = false;
8484
std::exit(0);
85-
8685
return true;
8786
}
8887
return false;

source/src/finder.exe

435 KB
Binary file not shown.

source/src/threadPool.cc

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "../include/threadPool.hh"
22

33
#include <cstddef>
4+
#include <cstdlib>
45
#include <functional>
56
#include <mutex>
67

@@ -10,7 +11,12 @@ ThreadPool::ThreadPool(size_t threadCount) {
1011
}
1112
}
1213

13-
ThreadPool::~ThreadPool() { stopPool(); }
14+
ThreadPool::~ThreadPool() {
15+
std::cout << "hello";
16+
stopPool();
17+
}
18+
19+
std::atexit(stopPool);
1420

1521
void ThreadPool::stopPool() {
1622
stop = true;

0 commit comments

Comments
 (0)