![](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FJJFmf%2FbtqFknot3BF%2Fb6HfwdChgXekjIl0L9K7r1%2Fimg.png)
Mutex์์ ๋น๊ต ์ฝ๋ #include #include #include #include #include #include using namespace std; class Node { public: int value; Node* next; Node() : value(0) { next = NULL; } Node(int k_value) { next = NULL; value = k_value; } }; int node_n; //random ๊ตฌํ random_device rd; mt19937 gen(rd()); uniform_int_distribution dis(0, 10); //์ถ๋ ฅ์ ์ํ mutex mutex mut; class LFStack { private: Node * head; public: void ..
![](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fbv73sJ%2FbtqFjqsteHV%2FLp86vxVJklmxN2vQUP1ZT0%2Fimg.png)
๋ชฉ์ฐจ ๋ฌธ์ ์ ์ lock free ๊ตฌํ ABA ํด๊ฒฐ intํ ๊ตฌํ(+ Hazard pointer) Counter ๊ทธ ์ธ์ ๋ฐฉ๋ฒ๋ค mutex lock(spin lock)๊ณผ์ ๋น๊ต ๊ทธ ์ธ์ ๋ฐฉ๋ฒ๋ค DCAS _InterlockedCompareExchange128 ์ฌ์ฉ ์์ Counter ๊ธฐ๋ฒ๊ณผ ๋น์ทํ๋ค. 64bit๋ฅผ ๋ชจ๋ ์ด์ฉํ์ฌ ์ฃผ์๋ฅผ ํํํ๋ CPU์์๋ ์์ Counter ๊ธฐ๋ฒ์ ์ฌ์ฉํ ์ ์์ผ๋ฏ๋ก c++์ _InterlockedCompareExchange128 ์ฐ์ฐ์ ์ด์ฉํ์ฌ ์ด๋ฅผ ๋์ ํ ์ ์๋ค. ์ด ์ฐ์ฐ์ 64bit ์๋ฃํ 2๊ฐ๋ฅผ ๋ฌถ์ด์ 128bit๋ก CAS ์ฐ์ฐ์ ์ํํ ์ ์๋ค. ์ด ๋ 64bit ์ฉ ๋ถ๋ฆฌํ์ฌ ์๋ก์ด ๊ฐ์ผ๋ก ๋ฐ๊พธ์ด์ค ์ ์๋ค. lock ๋ณ์ ์ด์ฉ ์ด์ ๋ธ๋ฆฌ์ด๊น์ง ๋ณด๋ฉด lock-fr..
![](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcsOmfE%2FbtqFjrdQrZE%2Fe4AR6SSbzKSvaOhwBddhJ1%2Fimg.png)
๋ชฉ์ฐจ ๋ฌธ์ ์ ์ lock free ๊ตฌํ ABA ํด๊ฒฐ intํ ๊ตฌํ(+ Hazard pointer) Counter ๊ทธ ์ธ์ ๋ฐฉ๋ฒ๋ค mutex lock(spin lock)๊ณผ์ ๋น๊ต Counter #include #include #include #include #include #include using namespace std; class Node { public: int value; Node* next; Node() : value(0) { next = NULL; } Node(int k_value) { next = NULL; value = k_value; } }; int node_n; //random ๊ตฌํ random_device rd; mt19937 gen(rd()); uniform_int_distribut..
![](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcRRLKZ%2FbtqFiPe8a0w%2FZxvuUUmkmmeZjj3K8uwlG1%2Fimg.png)
๋ชฉ์ฐจ ๋ฌธ์ ์ ์ lock free ๊ตฌํ ABA ํด๊ฒฐ intํ ๊ตฌํ(+ Hazard pointer) Counter ๊ทธ ์ธ์ ๋ฐฉ๋ฒ๋ค mutex lock(spin lock)๊ณผ์ ๋น๊ต Hazard Pointer https://m.blog.naver.com/PostView.nhn?blogId=jjoommnn&logNo=130127286459&proxyReferer=https:%2F%2Fwww.google.com%2F ๋ฅผ ์ฐธ๊ณ ํ์ฌ ์์ฑํ์๋ค. ๋ฌธ์ ์ ๋จผ์ delete๋ฅผ ์ด์ฉํ์ฌ ๊ฐ์ฒด๋ฅผ ์ญ์ ํ๋ฉด, ํด๋น ๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ๊ณ ์๋ ์ค๋ ๋์ ๋ฌธ์ ๊ฐ ์๊ธธ ์๋ ์๊ณ ๊ฐ์ฒด๊ฐ ์ญ์ ๋ ์ฃผ์์ ๋ค์ ๊ฐ์ ๊ฐ์ฒด๊ฐ ํ ๋น๋์ด ABA ๋ฌธ์ ๊ฐ ์ผ์ด๋ ๊ฐ๋ฅ์ฑ์ด ์๋ค. ์๋ก ๊ฐ์ฒด๋ฅผ ํ ๋นํ๋ ๊ฒ์ ์ฌ์ฉ์๊ฐ ๊ด๋ฆฌํ๋ list๊ฐ ์๋๋ค. 1๋ฒ ๋ฌธ์ ๋ฅผ ..
![](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FOjB36%2FbtqFkTmUKuW%2FbKsCRCkdSNrofeZiKXfsQ1%2Fimg.png)
๋ชฉ์ฐจ ๋ฌธ์ ์ ์ lock free ๊ตฌํ ABA ํด๊ฒฐ intํ ๊ตฌํ(+ Hazard pointer) Counter ๊ทธ ์ธ์ ๋ฐฉ๋ฒ๋ค mutex lock(spin lock)๊ณผ์ ๋น๊ต ABA ํด๊ฒฐ intํ ๊ตฌํ ABA ๋ฌธ์ ๋ ๋งค๊ฐ๋ณ์๋ฅผ intํ์ผ๋ก ๊ตฌํํ๋ฉด ์ฝ๊ฒ ํด๊ฒฐํ ์ ์๋ค. ํ์ง๋ง ๋ฌธ์ ์ ์ ์กด์ฌํ๋ค(๋ท๋ถ๋ถ์ ์ธ๊ธ). ์ฝ๋ #define _CRT_SECURE_NO_WARNINGS #define NULL_INT -1 // NULL ๊ฐ #include #include #include #include #include // #include #include using namespace std; struct Node { int data; Node* next_node; }; int node_n; atomic free_l..
![](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbBzMF7%2FbtqFhKL6ZAe%2FbfVR0LOB3fiKCs8hZs3vgK%2Fimg.png)
๋ชฉ์ฐจ ๋ฌธ์ ์ ์ lock free ๊ตฌํ ABA ํด๊ฒฐ intํ ๊ตฌํ(+ Hazard pointer) Counter ๊ทธ ์ธ์ ๋ฐฉ๋ฒ๋ค mutex lock(spin lock)๊ณผ์ ๋น๊ต ๋ฌธ์ ์ ์ ๋ฌธ์ Linked List ์๋ฃ๊ตฌ์กฐ์์ push()์ pop() ์ฐ์ฐ์ ๊ตฌํํ๋ค. Linked List๋ FreeList์ HeadList ๋๊ฐ์ง๊ฐ ์์ผ๋ฉฐ ์ฌ๋ฌ ์ค๋ ๋๊ฐ ๋ ๊ฐ์ List๋ฅผ ๋ฒ๊ฐ์๊ฐ๋ฉฐ push, pop ์ฐ์ฐ์ ์ํํ๋ค. ์ค๋ ๋๋ค์ด ๊ฐ๊ฐ ์ฐ์ฐ์ ์ํํ๊ธฐ ์ํด์๋ List๋ค์ ๋ํ ์ํธ๋ฐฐ์ ๊ฐ ํ์ํ๋ค. ํด์ ์ํธ ๋ฐฐ์ ์๋ ์ฌ๋ฌ๊ฐ์ง ๋ฐฉ๋ฒ์ด ์์ง๋ง, ํฌ๊ฒ ๋๊ฐ์ง๋ก ๋๋ ์ ์๋ค. lock ๋ณ์์ ์กฐ๊ฑด์ ์ฒดํฌํ๋ฉฐ ๋ฐ๋ณต๋ฌธ์ ๋๊ณ ์๋ spin lock๊ณผ, lock ๋ณ์ ์์ด ๊ณ์ ์๋ํ๋ฉด์ ์ ์ ํ ๋์ ๋์์ ์ํ..
Comment