이 블로그 검색

레이블이 c++인 게시물을 표시합니다. 모든 게시물 표시
레이블이 c++인 게시물을 표시합니다. 모든 게시물 표시

2017년 12월 3일 일요일

localtime_r 은 thread safe 하지 않다? deadlock발생 경우.

며칠 전 개발하면서 겪었던 상황인데,
fork 된 child process에서는 localtime_r 과 같은 시간관련 함수를 사용할때 유의해야 한다.

2011년 9월 20일 화요일

protothread : Duff's device

protothread 란 것을 보던중에 아래와 같은 소스를 발견.
그동안 몰랐던 이상야릇한 C언어 switch 구문형태이다~

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
int counter = 0;
int n = 0;

int somefun()
{
    switch(n){
        case 0: 
   while(1){
     n = 12; 
     case 12:
     if(!(counter == 1000))
         return 0;       
     printf("Threshold reached\n");
     counter = 0;
 }
    }
    n = 0;  
    return 2;
}

int _tmain(int argc, _TCHAR* argv[])
{
 somefun(); // case 0
 somefun(); // case 12
 return 0;
}
Pastie #2495563 linked directly from Pastie.