aboutsummaryrefslogtreecommitdiff
path: root/works/life
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-06-12 23:20:15 +0800
committercrupest <crupest@outlook.com>2021-06-12 23:25:49 +0800
commitdc0dfeec23158268268da5a16364abb1f0de5a06 (patch)
tree845fb99b4f5d80cc5a99019d5af8598abf5f7e45 /works/life
parent2c7ceca3e58543c36098fd46de711d9cd80a4d12 (diff)
downloadcrupest-dc0dfeec23158268268da5a16364abb1f0de5a06.tar.gz
crupest-dc0dfeec23158268268da5a16364abb1f0de5a06.tar.bz2
crupest-dc0dfeec23158268268da5a16364abb1f0de5a06.zip
import(life): ...
Diffstat (limited to 'works/life')
-rw-r--r--works/life/operating-system-experiment/CMakeLists.txt2
-rw-r--r--works/life/operating-system-experiment/DeadLockDetectionDemo.cpp25
-rw-r--r--works/life/operating-system-experiment/ParallelCalculationDemo.cpp2
-rw-r--r--works/life/operating-system-experiment/Thread.h8
4 files changed, 29 insertions, 8 deletions
diff --git a/works/life/operating-system-experiment/CMakeLists.txt b/works/life/operating-system-experiment/CMakeLists.txt
index 5671b4a..79fe786 100644
--- a/works/life/operating-system-experiment/CMakeLists.txt
+++ b/works/life/operating-system-experiment/CMakeLists.txt
@@ -33,3 +33,5 @@ target_link_libraries(semaphore_avoid_data_race_demo PRIVATE cru_system)
add_executable(parallel_calculation_demo ParallelCalculationDemo.cpp)
target_link_libraries(parallel_calculation_demo PRIVATE cru_system)
+
+add_executable(dead_lock_detection_demo DeadLockDetectionDemo.cpp)
diff --git a/works/life/operating-system-experiment/DeadLockDetectionDemo.cpp b/works/life/operating-system-experiment/DeadLockDetectionDemo.cpp
new file mode 100644
index 0000000..b22549e
--- /dev/null
+++ b/works/life/operating-system-experiment/DeadLockDetectionDemo.cpp
@@ -0,0 +1,25 @@
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+int main() {
+ std::vector<int> ns;
+
+ while (!std::cin.eof() || std::cin) {
+ int n;
+ std::cin >> n;
+ ns.push_back(n);
+ }
+
+ if (!std::cin.eof()) {
+ std::cerr << "Failed to parse input.\n";
+ return -1;
+ }
+
+ if (ns.size() % 2 != 0) {
+ std::cerr << "Input integer number must be even.\n";
+ return -1;
+ }
+
+
+}
diff --git a/works/life/operating-system-experiment/ParallelCalculationDemo.cpp b/works/life/operating-system-experiment/ParallelCalculationDemo.cpp
index 7340da8..0174c55 100644
--- a/works/life/operating-system-experiment/ParallelCalculationDemo.cpp
+++ b/works/life/operating-system-experiment/ParallelCalculationDemo.cpp
@@ -12,9 +12,11 @@ int main(int argc, char **argv) {
thread_number = std::atoi(argv[1]);
if (thread_number <= 0) {
std::cerr << "Argument must be a positive integer.\n";
+ return -1;
}
} else {
std::cerr << "Too many arguments.\n";
+ return -1;
}
std::cout << "Use " << thread_number << " threads to calculate sum of 1-" << N
diff --git a/works/life/operating-system-experiment/Thread.h b/works/life/operating-system-experiment/Thread.h
index 735407c..4ad1ef4 100644
--- a/works/life/operating-system-experiment/Thread.h
+++ b/works/life/operating-system-experiment/Thread.h
@@ -66,14 +66,6 @@ private:
#endif
};
-namespace details {
-#ifdef CRU_WINDOWS
-CRU_API DWORD WINAPI ThreadProc(_In_ LPVOID lpParameter);
-#else
-void *ThreadProc(void *data);
-#endif
-} // namespace details
-
template <typename Fn, typename... Args>
Thread::Thread(Fn &&process, Args &&...args) {
std::tuple<std::decay_t<Args>...> a{std::forward<Args>(args)...};