******** 01_소개
**** 2-91
scene traversal (see scene graph)
http://en.wikipedia.org/wiki/Scene_graph
Stencil shadow extrusion (see Shadow Volume)
http://en.wikipedia.org/wiki/Shadow_volume
**** 2-97 select()
http://linux.die.net/man/2/select
**** 2-100 add_timer()
http://www.tldp.org/LDP/khg/HyperNews/get/devices/reference.html
******** 02_멀티쓰레드프로그래밍
**** 컴파일러 - Volatile 위치 오류의 예
see How to use C's volatile keyword
http://www.barrgroup.com/Embedded-Systems/How-To/C-Volatile-Keyword
Top-Level cv-Qualifiers in Function Parameters
http://www.dansaks.com/articles/2000-02%20Top-Level%20cv-Qualifiers%20in%20Function%20Parameters.pdf
******** 03_메모리 일관성
**** 메모리 일관성 -실습 #14
see 메모리 배리어(변수들 사이의 종속성과 관련한 설명)
http://ko.wikipedia.org/wiki/%EB%A9%94%EB%AA%A8%EB%A6%AC_%EB%B0%B0%EB%A6%AC%EC%96%B4
memory barrier
http://en.wikipedia.org/wiki/Memory_barrier
Out-of-Order(CPU)
(are Intel CPUs CISC or RISC? see AMD versus Intel: Successes and pitfalls of their processor architectures)
http://www.programcreek.com/2012/12/amd-versus-intel-successes-and-pitfalls-of-their-processor-architectures-2-bulldozer-and-sandy-bridge-comparison/
**** 메모리 일관성 -실습 15
(project mt3)
#include #include
#define THREAD_MAX 2 #define SIZE 10000000 volatile int x, y; int trace_x[SIZE], trace_y[SIZE];
DWORD WINAPI ThreadFunc1(LPVOID lpVoid) { for (int i=0; i < SIZE; i++) { x = i; trace_y[i] = y; } return 0; }
DWORD WINAPI ThreadFunc2(LPVOID lpVoid) { for (int i=0; i < SIZE; i++) { y = i; trace_x[i] = x; } return 0; }
int main() { DWORD addr; HANDLE hThread1 = CreateThread( NULL, 0, ThreadFunc1, NULL, 0, &addr); HANDLE hThread2 = CreateThread( NULL, 0, ThreadFunc2, NULL, 0, &addr); WaitForSingleObject( hThread1, INFINITE); WaitForSingleObject( hThread2, INFINITE); CloseHandle( hThread1); CloseHandle( hThread2);
int count = 0; for (int i = 0; i < SIZE; ++i) if (trace_x[i] == trace_x[i+1]) if (trace_y[trace_x[i]] == trace_y[trace_x[i] + 1]) { if (trace_y[trace_x[i]] != i) continue; count ++; } printf("Total Memory Inconsistency count is %d\n", count); getchar(); return 0; }
===> in Console: Total Memory Inconsistency count is 185
**** 메모리 일관성 -실습 16
(project mt2)
#include #include
bool done = false;
volatile int *bound; int error;
DWORD WINAPI ThreadFunc1(LPVOID lpVoid) { for (int j=0; j <= 25000000; ++j) *bound = -(1 + *bound); done = true; return 0; }
DWORD WINAPI ThreadFunc2(LPVOID lpVoid) { while (!done) { int v = *bound; if ((v != 0) && (v != -1)) error ++; } return 0; }
int main() { int b; bound = &b; *bound = 0;
DWORD addr; HANDLE hThread1 = CreateThread( NULL, 0, ThreadFunc1, NULL, 0, &addr); HANDLE hThread2 = CreateThread( NULL, 0, ThreadFunc2, NULL, 0, &addr); WaitForSingleObject( hThread1, INFINITE); WaitForSingleObject( hThread2, INFINITE); CloseHandle( hThread1); CloseHandle( hThread2); printf("Error count is %d\n", error); getchar(); return 0; }
===> in Colsole: Error count is 0
**** 메모리 일관성 -실습 17
(project mt2_1)
#include #include
bool done = false; volatile int *bound; int error;
DWORD WINAPI ThreadFunc1(LPVOID lpVoid) { for (int j=0; j <= 25000000; ++j) *bound = -(1 + *bound); done = true; return 0; }
DWORD WINAPI ThreadFunc2(LPVOID lpVoid) { while (!done) { int v = *bound; if ((v != 0) && (v != -1)) error ++; } return 0; }
int main() { int ARR[32];
int temp = (int) &ARR[16]; temp = temp & 0xFFFFFFC0; // to round down temp to the nearest lower address in 32-byte blocks (maybe cache line size?) temp -= 2; // to make temp points a 4-byte int which is on two 32-byte blocks bound = (int *) temp; // now bound points the 4-byte int *bound = 0;
DWORD addr; HANDLE hThread1 = CreateThread( NULL, 0, ThreadFunc1, NULL, 0, &addr); HANDLE hThread2 = CreateThread( NULL, 0, ThreadFunc2, NULL, 0, &addr); WaitForSingleObject( hThread1, INFINITE); WaitForSingleObject( hThread2, INFINITE); CloseHandle( hThread1); CloseHandle( hThread2); printf("Error count is %d\n", error); getchar(); return 0; }
===> in Colsole: Error count is 102177
|