diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-02-28 23:13:39 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-02-28 23:13:39 +0800 |
commit | dc1f0c4c0096013799416664894c5194dc7e1f52 (patch) | |
tree | 2f5d235f778cd720f4c39ec3e56b77ba6d99f375 /works/life/operating-system-challenge | |
parent | 7299d424d90b1effb6db69e3476ddd5af72eeba4 (diff) | |
download | crupest-dc1f0c4c0096013799416664894c5194dc7e1f52.tar.gz crupest-dc1f0c4c0096013799416664894c5194dc7e1f52.tar.bz2 crupest-dc1f0c4c0096013799416664894c5194dc7e1f52.zip |
chore(store): move everything to store.
Diffstat (limited to 'works/life/operating-system-challenge')
-rw-r--r-- | works/life/operating-system-challenge/.gitignore | 1 | ||||
-rw-r--r-- | works/life/operating-system-challenge/1/README.md | 10 | ||||
-rw-r--r-- | works/life/operating-system-challenge/1/effect.png | bin | 136979 -> 0 bytes | |||
-rw-r--r-- | works/life/operating-system-challenge/1/main.cpp | 33 | ||||
-rw-r--r-- | works/life/operating-system-challenge/1/sample.jpg | bin | 125777 -> 0 bytes | |||
-rw-r--r-- | works/life/operating-system-challenge/2/README.md | 10 | ||||
-rw-r--r-- | works/life/operating-system-challenge/2/effect.png | bin | 179599 -> 0 bytes | |||
-rw-r--r-- | works/life/operating-system-challenge/2/main.cpp | 73 | ||||
-rw-r--r-- | works/life/operating-system-challenge/2/sample.jpg | bin | 82879 -> 0 bytes | |||
-rw-r--r-- | works/life/operating-system-challenge/3/README.md | 5 | ||||
-rw-r--r-- | works/life/operating-system-challenge/3/main.cpp | 68 | ||||
-rw-r--r-- | works/life/operating-system-challenge/3/problem.jpg | bin | 25702 -> 0 bytes | |||
-rw-r--r-- | works/life/operating-system-challenge/README.md | 1 |
13 files changed, 0 insertions, 201 deletions
diff --git a/works/life/operating-system-challenge/.gitignore b/works/life/operating-system-challenge/.gitignore deleted file mode 100644 index 1feae78..0000000 --- a/works/life/operating-system-challenge/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.exe
diff --git a/works/life/operating-system-challenge/1/README.md b/works/life/operating-system-challenge/1/README.md deleted file mode 100644 index db7b627..0000000 --- a/works/life/operating-system-challenge/1/README.md +++ /dev/null @@ -1,10 +0,0 @@ -> 挑战一:写一个程序,运行该进程时,你的电脑整体 CPU 利用率保持在 100%
-> 示例效果如
-> 
-
-Transaltion: Write a program and make your CPU's usage rate 100%.
-
-Code is in `main.cpp`. Remember to not compile it with O2 optimization, or my dead loop will be eliminated.
-
-Final effect:
-
diff --git a/works/life/operating-system-challenge/1/effect.png b/works/life/operating-system-challenge/1/effect.png Binary files differdeleted file mode 100644 index b173ea0..0000000 --- a/works/life/operating-system-challenge/1/effect.png +++ /dev/null diff --git a/works/life/operating-system-challenge/1/main.cpp b/works/life/operating-system-challenge/1/main.cpp deleted file mode 100644 index 0f780ef..0000000 --- a/works/life/operating-system-challenge/1/main.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Remember not to use O2 optimization!
-
-#include <thread>
-#include <vector>
-
-int main() {
- std::vector<std::thread> threads;
-
- // Because my CPU has 4-core and 8-threads. I open 8 threads.
- for (int i = 0; i < 8; i++) {
- std::thread t([] {
- int i;
- int j;
- int k;
- double d;
- while (true) {
- i = i + i;
- j = j - j;
- k = k * k;
- d = d + d;
- i = i & i;
- j = j | j;
- }
- });
- threads.push_back(std::move(t));
- }
-
- for (auto &t : threads) {
- t.join();
- }
-
- return 0;
-}
diff --git a/works/life/operating-system-challenge/1/sample.jpg b/works/life/operating-system-challenge/1/sample.jpg Binary files differdeleted file mode 100644 index 7276bec..0000000 --- a/works/life/operating-system-challenge/1/sample.jpg +++ /dev/null diff --git a/works/life/operating-system-challenge/2/README.md b/works/life/operating-system-challenge/2/README.md deleted file mode 100644 index 86672f5..0000000 --- a/works/life/operating-system-challenge/2/README.md +++ /dev/null @@ -1,10 +0,0 @@ -> 挑战二:写一个程序,运行该进程时,你计算机每一个核的 CPU 占用率是各不相同的有规律的曲线
-> 示例效果如:
-> 
-
-Translation: Write a program and make each core of your CPU get a different but regular usage rate graph.
-
-Code is in `main.cpp`. Remember to not compile it with O2 optimization, or my loop will be eliminated.
-
-Final effect:
-
diff --git a/works/life/operating-system-challenge/2/effect.png b/works/life/operating-system-challenge/2/effect.png Binary files differdeleted file mode 100644 index 984a3da..0000000 --- a/works/life/operating-system-challenge/2/effect.png +++ /dev/null diff --git a/works/life/operating-system-challenge/2/main.cpp b/works/life/operating-system-challenge/2/main.cpp deleted file mode 100644 index a497442..0000000 --- a/works/life/operating-system-challenge/2/main.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include <Windows.h>
-#include <cmath>
-
-DWORD WINAPI Thread1(_In_ LPVOID lpParameter) {
- int i;
- while (true) {
- i++;
- }
- return 0;
-}
-
-DWORD WINAPI Thread2(_In_ LPVOID lpParameter) {
- while (true) {
- for (long long i = 0; i < 5000000000; i++)
- ;
- Sleep(10000);
- }
-
- return 0;
-}
-
-DWORD WINAPI Thread3(_In_ LPVOID lpParameter) {
- while (true) {
- for (int i = 0; i < 4000000; i++)
- ;
- Sleep(10);
- }
-
- return 0;
-}
-
-DWORD WINAPI Thread4(_In_ LPVOID lpParameter) {
- LARGE_INTEGER frequency;
- QueryPerformanceFrequency(&frequency);
-
- LARGE_INTEGER count;
- QueryPerformanceCounter(&count);
-
- double current_y = 0;
-
- while (true) {
- for (int i = 0; i < 3000000.0 * (1.0 + current_y); i++)
- ;
- Sleep(10 * (1 - current_y));
-
- LARGE_INTEGER new_count;
- QueryPerformanceCounter(&new_count);
-
- auto s = (new_count.QuadPart - count.QuadPart) / frequency.QuadPart;
- current_y = std::sin(s / 30.0 * 2 * 3.1415926535) * 0.6;
- }
-
- return 0;
-}
-
-int main() {
- HANDLE thread1 = CreateThread(NULL, 0, Thread1, NULL, 0, NULL);
- HANDLE thread2 = CreateThread(NULL, 0, Thread2, NULL, 0, NULL);
- HANDLE thread3 = CreateThread(NULL, 0, Thread3, NULL, 0, NULL);
- HANDLE thread4 = CreateThread(NULL, 0, Thread4, NULL, 0, NULL);
-
- SetThreadAffinityMask(thread1, 1);
- SetThreadAffinityMask(thread2, 1 << 1);
- SetThreadAffinityMask(thread3, 1 << 2);
- SetThreadAffinityMask(thread4, 1 << 3);
-
- WaitForSingleObject(thread1, INFINITE);
- WaitForSingleObject(thread2, INFINITE);
- WaitForSingleObject(thread3, INFINITE);
- WaitForSingleObject(thread4, INFINITE);
-
- return 0;
-}
diff --git a/works/life/operating-system-challenge/2/sample.jpg b/works/life/operating-system-challenge/2/sample.jpg Binary files differdeleted file mode 100644 index 53b9f89..0000000 --- a/works/life/operating-system-challenge/2/sample.jpg +++ /dev/null diff --git a/works/life/operating-system-challenge/3/README.md b/works/life/operating-system-challenge/3/README.md deleted file mode 100644 index 63fa023..0000000 --- a/works/life/operating-system-challenge/3/README.md +++ /dev/null @@ -1,5 +0,0 @@ -
-
-Translation: Use a lock to achieve that 3 threads print A, B, C in turn for 10 times. Output is `ABCABC...`
-
-Code is in `main.cpp`.
diff --git a/works/life/operating-system-challenge/3/main.cpp b/works/life/operating-system-challenge/3/main.cpp deleted file mode 100644 index 461c775..0000000 --- a/works/life/operating-system-challenge/3/main.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include <iostream>
-#include <mutex>
-#include <thread>
-
-int main() {
- int turn = 1;
- int count = 0;
- std::mutex mutex;
-
- auto thread_proc1 = [&] {
- while (true) {
- {
- std::lock_guard<std::mutex> guard(mutex);
- if (count >= 10)
- break;
- if (turn == 1) {
- std::cout << "A" << std::endl;
- turn = 2;
- }
- }
-
- std::this_thread::yield();
- }
- };
-
- auto thread_proc2 = [&] {
- while (true) {
- {
- std::lock_guard<std::mutex> guard(mutex);
- if (count >= 10)
- break;
- if (turn == 2) {
- std::cout << "B" << std::endl;
- turn = 3;
- }
- }
-
- std::this_thread::yield();
- }
- };
-
- auto thread_proc3 = [&] {
- while (true) {
- {
- std::lock_guard<std::mutex> guard(mutex);
- if (count >= 10)
- break;
- if (turn == 3) {
- std::cout << "C" << std::endl;
- turn = 1;
- count++;
- }
- }
-
- std::this_thread::yield();
- }
- };
-
- std::thread thread1(thread_proc1);
- std::thread thread2(thread_proc2);
- std::thread thread3(thread_proc3);
-
- thread1.join();
- thread2.join();
- thread3.join();
-
- return 0;
-}
diff --git a/works/life/operating-system-challenge/3/problem.jpg b/works/life/operating-system-challenge/3/problem.jpg Binary files differdeleted file mode 100644 index c3a61b7..0000000 --- a/works/life/operating-system-challenge/3/problem.jpg +++ /dev/null diff --git a/works/life/operating-system-challenge/README.md b/works/life/operating-system-challenge/README.md deleted file mode 100644 index 8a5898d..0000000 --- a/works/life/operating-system-challenge/README.md +++ /dev/null @@ -1 +0,0 @@ -Some challenges raised by my Operating System teacher, aka. Li Hao.
|