티스토리 뷰
https://code.google.com/p/semicomplete/source/browse/codesamples/exponential-backoff.c
아래는 exponential backoff관련 코드이다.
#include <stdio.h> |
#include <unistd.h> |
void exponential_backoff(useconds_t *current, useconds_t maxwait) { |
usleep(*current); |
*current *= 2; |
if (*current >= maxwait) { |
*current = maxwait; |
} |
} /* void exponential_backoff(useconds_t *, useconds_t) */ |
int main() { |
useconds_t maxwait = 5000000; /* 5 seconds */ |
useconds_t current = 2000; /* Start with 2ms */ |
/* abort when we get to maxwait */ |
while (current < maxwait) { |
printf("Sleeping for %d\n", current); |
exponential_backoff(¤t, maxwait); |
} |
return 0; |
} |
'프로그래밍Tip' 카테고리의 다른 글
WinMain vs main 그리고 유니코드(w~) (0) | 2013.07.10 |
---|---|
Mongoose - 임베디드 웹서버 (0) | 2013.07.10 |
tdelete(_)의 모범사용 (0) | 2013.07.08 |
tsearch code sample (0) | 2013.07.08 |
Knuth(tfind, tsearch, ...) example (0) | 2013.07.08 |
공지사항