We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7c96a10 commit 4143f08Copy full SHA for 4143f08
src/CacheManager.cpp
@@ -19,9 +19,15 @@ void CacheManager::accessCache(int key, int value) {
19
}
20
21
22
-void CacheManager::switchPolicy() {
23
- while (true) {
24
- std::this_thread::sleep_for(std::chrono::seconds(5));
+// Modified to use the stop flag
+void CacheManager::switchPolicy(std::atomic<bool>& stop_flag) {
+ // Loop only until the flag is set to true
25
+ while (!stop_flag.load()) {
26
+ std::this_thread::sleep_for(std::chrono::seconds(2)); // Shortened for test
27
+
28
+ // Check the flag again in case it was set while sleeping
29
+ if (stop_flag.load()) break;
30
31
setPolicy(current_policy == LFU ? LRU : LFU);
32
std::cout << "Cache policy switched!" << std::endl;
33
0 commit comments