Nokia QT 개발환경 세팅중

Posted at 2010/06/12 08:05 // in Programming // by Daniel

http://developer.symbian.org/wiki/index ··· ck_start

image

노키아가 QT를 조만간 기본 환경으로 쓸 거라고 해서

(자바로 할까 했으나)

일단 이걸로 개발해보기로 했습니다. (..하지만 시간이 있을 지 과연..)

 

http://www.forum.nokia.com/info/sw.noki ··· sdk.html

image

image

크리에이티브 커먼즈 라이센스
Creative Commons License

No silver Bullet

Posted at 2010/04/22 10:14 // in Programming // by Daniel
The Mythical Man-month에 나온 이야기
유명한 페이퍼입니다.

소프트웨어 개발에 하나의 방법으로 모든 도메인에 일정과 품질을 향상시키는 "마법의 탄환"은 없다는거죠 :-)
pdf 출처는 http://people.eecs.ku.edu/~saiedian/Teaching/Sp08/816/Papers/Background-Papers/no-silver-bullet.pdf 입니다. 구글검색 :-)

크리에이티브 커먼즈 라이센스
Creative Commons License

간단한 FIFO queue 예제

Posted at 2010/04/22 08:35 // in Programming // by Daniel

#include <stdio.h>

static char qout( void );
static int qin( char in );
static int  qlen ( void );
#define Q_MAX   4
int queue[Q_MAX];
int qhead=0;
int qtail=0;
int main(void)
{
    char io;
    char input;
    int exit=0;
    int state=0;
    char rd;
    printf("simple queue test\n");
    fflush(stdin);
    do {
        switch(state) {
            case 0:
                printf("cmd $ ");
                state = 1;
            case 1:
                fflush(stdout);
                fflush(stdin);
                rd = getchar();
                if (rd==' ' || rd=='\n')
                    continue;
                if (rd=='q') {
                    exit=1;
                    break;
                }
                // get cmd;
                if (rd=='i')
                    state = 5;
                if (rd=='o')
                    state = 10;
                break;
            case 5:
                // input
                printf("input$ ");
                state = 6;
            case 6:
                fflush(stdout);
                fflush(stdin);
                rd = getchar();
                if (rd==' ' || rd=='\n')
                    continue;
                if (rd=='q') {
                    exit=1;
                    break;
                }
                input = rd;
                qin(input);
                printf("h=%d, tail=%d qlen=%d\n", qhead, qtail, qlen());
                state = 0;
                break;
            case 10:
                // get

                printf("%c\n", qout());
                printf("h=%d, tail=%d qlen=%d\n", qhead, qtail, qlen());
                state = 0;
                break;
            default:
                printf("default state??\n");
                exit=1;
        } // switch
    } while(!exit);

    return 0;
}

static int  qlen ( void )
{
    if ( qhead >= qtail )
        return qhead-qtail;
    return qhead+Q_MAX+1-qtail;
}

static int qin( char in )
{
    int tmp_head = qhead;
    tmp_head++;
    if (tmp_head==(Q_MAX+1))
        tmp_head=0;
    if (tmp_head==qtail) {
        // overrun
        fprintf(stderr, "q overrun\n");
        return -1;
    }
    printf("q[%d]<:=%c\n", qhead, in);
    queue[qhead] = in;
    qhead = tmp_head;
    return 0;
}

static char qout( void )
{
    int tmp_tail = qtail;
    if (qtail == qhead) {
        // underrun
        fprintf(stderr, "q underrun\n");
        return '\b';
    }
    qtail = (tmp_tail +1 );
    if (qtail == (Q_MAX+1))
        qtail = 0;
    printf("q[%d]==%c\n", tmp_tail, queue[tmp_tail]);
    return queue[tmp_tail];
}

리팩토링 필요 – 리팩토링 했지만 여기에 게시하진 않음.
크리에이티브 커먼즈 라이센스
Creative Commons License

(C프로그램) 매크로 정의시 안전한 방법

Posted at 2010/04/20 10:31 // in Programming // by Daniel

do { ... } while(0)로 묶기

http://kernelnewbies.org/FAQ/DoWhile0, http://kldp.org/node/41390, http://blog.dasomoli.org/220

안전한 방법은 do{}while(0)로 묶는 것입니다.

#define foo(x) do{ printf(“it’s %d\n”, x); \
                 do_something(x);\
               } while (0)

일반적으로 C에서 매크로를 짜면

#define FOO(x) \
        printf("arg is %s\n", x); \
        do_something_useful(x);

이런 식으로 짜게 됩니다.

그러나 이런 방식은 맹점이 있습니다.

예를 들어

        if (blah == 2)
                FOO(blah);

이렇게 쓰면

        if (blah == 2)
                printf("arg is %s\n", blah);
                do_something_useful(blah);;

이렇게 해석돼 버립니다.

만일 do{ … }while(0)로 만들었다면

if (blah == 2)
        do {
                printf("arg is %s\n", blah);
                do_something_useful(blah);
        } while (0);

이렇게 원하는 대로 해석됩니다.

그렇다고

        #define exch(x,y) { int tmp; tmp=x; x=y; y=tmp; }

이렇게 쓰면

if (x > y)
        exch(x,y);          // Branch 1
else 
        do_something();     // Branch 2

이런 문장이

if (x > y) {                // Single-branch if-statement!!!
        int tmp;            // The one and only branch consists
        tmp = x;            // of the block.
        x = y;
        y = tmp;
}
;                           // empty statement
else                        // ERROR!!! "parse error before else"
        do_something();
이렇게 해석돼 버립니다. –> 컴파일러 에러 발생.
그러므로 do {} while(0)로 묶는 게 최고죠. 그래서 리눅스 커널에서 모든 매크로가 그렇게 돼 있는 겁니다.

매크로에서 쓰는 변수에는 괄호를 꼭 쳐주세요

그리고 한가지 더
매크로에서 쓰는 변수에는 괄호를 꼭 쳐주세요 http://www.oualline.com/style/c06.html

/* Square a number */
#define SQUARE(X) (x * x)
/* Bad practice, no () around parameter */

이렇게 정의하면
a = SQUARE(1 + 3);
-->:
a = (1 + 3 * 1 + 3);
이렇게 돼 버려서 원치 않는 결과가 나옵니다.
/* Square a number */
#define SQUARE(X) ((x) * (x))
이러면
a = ((l + 3) * (1 + 3));
이렇게 잘 나오겠지요.
크리에이티브 커먼즈 라이센스
Creative Commons License

Linux man page들

Posted at 2010/04/18 00:03 // in Programming // by Daniel
cygwin에선 glibc library man page가 없다.
왜냐면 당연히 cygwin이 linux가 아니므로;; (참고)

ubuntu 소스에서 man page를 가져와서 압축했다.
1.3메가.. posix 맨페이지도, 한글맨페이지도 받아다 압축했다.
 man-pages-3.23
man.tgz

Man pages. 1.3MB

man-ko.tgz

한글 man 페이지. 660KB

man-posix.tgz

POSIX man page - 이게 가장 필요할 듯. POSIX 표준관련 man page다. 1.3메가

cygwin에서 설치및 사용법
자기 홈디렉토리 아래
man 디렉토리를 만들고 그 아래에 man1~man8  디렉토리가 들어가도록 한다.
posix도 마찬가지로 man0p man1p man3p 디렉토리가 man 디렉토리 아래에 가도록 한다.
사용자 삽입 이미지

그리고,
~/.bash_profile에서
다음 구절을 추가하거나 주석 해제한다. 결국 당연히 man path를 추가하는 것임. (참고로 한글 man 페이지는 깔기를 추천하지 않음. 깨져나옴.)
# Set MANPATH so it includes users' private man if it exists
if [ -d "${HOME}/man" ]; then
  MANPATH=${HOME}/man:${MANPATH}
fi
# 한글 man페이지는 ~/man/ko에 깔면 되긴 되는데.. 추천하지 않음. 한글 깨집니다.
if [ -d "${HOME}/man/ko" ]; then
  MANPATH=${HOME}/man/ko:${MANPATH}
fi
사용자 삽입 이미지


크리에이티브 커먼즈 라이센스
Creative Commons License

Eddy DK 보드에 1ms 타이머 쓰기

Posted at 2010/03/17 23:19 // in Programming // by Daniel

지금 보드가 없으므로 검색 이후  말로만 하는 거임(틀릴 수 있음)

Eddy DK 보드는 CPU가 Atmel의 AT91SAM9260임

이 칩은 TC타이머가 6개 있음

그런데 Eddy DK의 OS인 레모닉스-리눅스를 조금 고친 것 같은데 소스를 일부만 줌-에서는 타이머 관련 코드가 살아있지 않음 (메모리 영역도 안잡혀있음. 소스를 안준 부분이 있어서 커널 컴파일도 다시 못함)

그래서 직접 하드웨어에 억세스하도록 하고 타이머 돌려보려고 했으나 실패(인터럽트는 커녕 타이머 자체가 돌지 않음)

결국 외부 GPIO에 붙여서 인터럽트 걸어서 사용

 

인터넷을 검색해본 결과 두 가지를 알 수 있었음

1. hrtimer를 쓰면 된다고 하는 사람이 있음

hrtimer는 config에 있는 것을 보았다 – 그런데 nanosleep같은 애들에서 쓴다던데 제대로 안됐다고 하는 거 같음

 

2. tclib이란 게 atmel에서 서포트한 코드가 커널에 있음

http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=67424

include/linux/atmel_tc.h and drivers/misc/atmel_tclib.c

drivers/clocksource/tcb_clksrc.c can be used as an example of how to use

tclib.

근데 레모닉스에는 일단 tclib이 enable안돼있음(config) 어찌됐든 코드를 붙여넣거나 해서 써야 함

 

 

참고

http://www.mail-archive.com/linux-kerne ··· 782.html
[patch 2.6.25-rc2-git 1/2] atmel_tc library

tclib이라고 원래 atmel 칩 용으로 타이머 라이브러리가 있음..

http://www.spinics.net/lists/arm-kernel/msg58764.html
Arg! Why is it always the case that I find the answer just after I submit the question ... I needed to SYNC the Timer Block. See below for correction.

> __raw_writel(1000, tcaddr + ATMEL_TC_REG(REG_OFFSET, RC));
> __raw_writel(0x0000, tcaddr + ATMEL_TC_REG(REG_OFFSET, RA));
> __raw_writel(0x0000, tcaddr + ATMEL_TC_REG(REG_OFFSET, RB));
> __raw_writel(0xff, tcaddr + ATMEL_TC_REG(REG_OFFSET, IDR));  /* no irqs */
> __raw_writel(ATMEL_TC_CLKEN, tcaddr + ATMEL_TC_REG(REG_OFFSET, CCR));
>
>  
__raw_writel(ATMEL_TC_SYNC, tcaddr + ATMEL_TC_BCR);
> at91_set_B_periph(AT91_PIN_PA19, 0);    /* TIOA1 */
>
> clocksource_register(&clksrc);
>
> ----- UNSNIP ----
>  
My device driver is probably deprecated by the new generic PWM lib from Bill, but I have to release with what I've got.

Aras

크리에이티브 커먼즈 라이센스
Creative Commons License

소프트웨어 크리에이티비티 2.0

Posted at 2009/05/25 14:47 // in Programming // by Daniel

http://jhrogue.blogspot.com/2009/05/20.html

소개받은책.

살까나

크리에이티브 커먼즈 라이센스
Creative Commons License

AT&T Assembly Syntax

Posted at 2009/05/04 11:33 // in Programming // by Daniel

http://sig9.com/articles/att-syntax

http://sourceware.org/binutils/docs-2.16/as/index.html

Updated: May/10 '06

This article is a 'quick-n-dirty' introduction to the AT&T assembly language syntax, as implemented in the GNU Assembler as(1). For the first timer the AT&T syntax may seem a bit confusing, but if you have any kind of assembly language programming background, it's easy to catch up once you have a few rules in mind. I assume you have some familiarity to what is commonly referred to as the INTEL-syntax for assembly language instructions, as described in the x86 manuals. Due to its simplicity, I use the NASM (Netwide Assembler) variant of the INTEL-syntax to cite differences between the formats.

The GNU assembler is a part of the GNU Binary Utilities (binutils), and a back-end to the GNU Compiler Collection. Although as is not the preferred assembler for writing reasonably big assembler programs, its a vital part of contemporary Unix-like systems, especially for kernel-level hacking. Often criticised for its cryptic AT&T-style syntax, it is argued that as was written with an emphasis on being used as a back-end to GCC, with little concern for "developer-friendliness". If you are an assembler programmer hailing from an INTEL-Syntax background, you'll experience a degree of stifling with regard to code-readability and code-generation. Nevertheless, it must be stated that, many operating systems' code-base depend on as as the assembler for generating low-level code.

The Basic Format

The structure of a program in AT&T-syntax is similar to any other assembler-syntax, consisting of a series of directives, labels, instructions - composed of a mnemonic followed by a maximum of three operands. The most prominent difference in the AT&T-syntax stems from the ordering of the operands.

For example, the general format of a basic data movement instruction in INTEL-syntax is,

mnemonic	destination, source

whereas, in the case of AT&T, the general format is

mnemonic	source, destination

To some (including myself), this format is more intuitive. The following sections describe the types of operands to AT&T assembler instructions for the x86 architecture.

Registers

All register names of the IA-32 architecture must be prefixed by a '%' sign, eg. %al,%bx, %ds, %cr0 etc.

mov	%ax, %bx

The above example is the mov instruction that moves the value from the 16-bit register AX to 16-bit register BX.

Literal Values

All literal values must be prefixed by a '$' sign. For example,

 		
mov	$100,	%bx
mov	$A,	%al

The first instruction moves the the value 100 into the register AX and the second one moves the numerical value of the ascii A into the AL register. To make things clearer, note that the below example is not a valid instruction,

mov	%bx,	$100

as it just tries to move the value in register bx to a literal value. It just doesn't make any sense.

Memory Addressing

In the AT&T Syntax, memory is referenced in the following way,

segment-override:signed-offset(base,index,scale)

parts of which can be omitted depending on the address you want.

%es:100(%eax,%ebx,2)

Please note that the offsets and the scale should not be prefixed by '$'. A few more examples with their equivalent NASM-syntax, should make things clearer,

GAS memory operand			NASM memory operand
------------------			-------------------

100					[100]
%es:100					[es:100]
(%eax)					[eax]
(%eax,%ebx)				[eax+ebx]
(%ecx,%ebx,2)				[ecx+ebx*2]
(,%ebx,2)				[ebx*2]
-10(%eax)				[eax-10]
%ds:-10(%ebp)				[ds:ebp-10]
Example instructions,
mov	%ax,	100
mov	%eax,	-100(%eax)

The first instruction moves the value in register AX into offset 100 of the data segment register (by default), and the second one moves the value in eax register to [eax-100].

Operand Sizes

At times, especially when moving literal values to memory, it becomes neccessary to specify the size-of-transfer or the operand-size. For example the instruction,

mov	$10,	100

only specfies that the value 10 is to be moved to the memory offset 100, but not the transfer size. In NASM this is done by adding the casting keyword byte/word/dword etc. to any of the operands. In AT&T syntax, this is done by adding a suffix - b/w/l - to the instruction. For example,

movb	$10,	%es:(%eax)

moves a byte value 10 to the memory location [ea:eax], whereas,

movl	$10,	%es:(%eax)

moves a long value (dword) 10 to the same place.

A few more examples,

movl	$100, %ebx
pushl	%eax
popw	%ax
Control Transfer Instructions

The jmp, call, ret, etc., instructions transfer the control from one part of a program to another. They can be classified as control transfers to the same code segment (near) or to different code segments (far). The possible types of branch addressing are - relative offset (label), register, memory operand, and segment-offset pointers.

Relative offsets, are specified using labels, as shown below.

label1:
	.
	.
  jmp	label1

Branch addressing using registers or memory operands must be prefixed by a '*'. To specify a "far" control tranfers, a 'l' must be prefixed, as in 'ljmp', 'lcall', etc. For example,

GAS syntax			NASM syntax
==========			===========

jmp	*100			jmp  near [100]
call	*100			call near [100]
jmp	*%eax			jmp  near eax
jmp	*%ecx			call near ecx
jmp	*(%eax)			jmp  near [eax]
call	*(%ebx)			call near [ebx]
ljmp	*100			jmp  far  [100]
lcall	*100			call far  [100]
ljmp	*(%eax)			jmp  far  [eax]
lcall	*(%ebx)			call far  [ebx]
ret				retn
lret				retf
lret $0x100			retf 0x100

Segment-offset pointers are specified using the following format:

jmp	$segment, $offset

For example:

jmp	$0x10, $0x100000
If you keep these few things in mind, you'll catch up real soon. As for more details on the GNU assembler, you could try the documentation.

By vivek on 2003-09-01

크리에이티브 커먼즈 라이센스
Creative Commons License

프로그래머에게 유용한 사이트들

Posted at 2009/04/24 15:47 // in Programming // by Daniel

메일을 받았는데 나중에 보려고 올려둡니다.

출처를 몰라서 표시 못합니다.

 

-----------------------------------------------------------------------------

CARES 여러분, 영호입니다.

며칠 전 shell script 문법 때문에 여기저기 사이트를 찾다가 프로그래머에게 유용한 사이트들을 모아놓은 블로그가 있어, 여러분도 참고하시라고 보내드립니다.

유용한 사이트들이 많으니 참고하세요

C/C++
ACM - The ABCs of Writing C++ Classes
Guru of the Week - Guru of the Week
STL - Standard C++ Library Tutorial 한글
STL - Standard C++ Library (SGI)
STL - Visual C++ 의 STL Sample
C++ FAQ - C++ FAQ
MSJ - Microsoft Systems Journal
VC++ STL Reference - VC++ STL Reference
Thinking in C++ - Thinking in C++ 온라인 북
코드 구루 - 코드 샘플이 많은 개발관련 사이트
OpenIL - Open Image Library
Win32ASM - Iczelion's Win32 Assembly Homepage
Priority Que & STL - by Mark Nelson (Dr. Dobb's Journal)
STLPort - 범용, 공개, 오픈소스 STL
데이타 압축 - 데이타 압축 관련 링크 모음
C++ Optimize - C++ 최적화 방법에 대한 내용
STL newbie - STL 초보자를 위한 문서
코드프로젝트 - 다양한 장르의 프로그래밍 강좌
MTL - Matrix Template Library
몇몇책들 - Effective C++, More Effective C++, Design Patterns
CPlusPlus - C++ Tutorial
AssemRef - Assembler Programmer's Reference
공짜 C/C++ 컴파일러들 - 공개 C/C++ 컴파일러들에 대한 상세한 목록
어셈러브 - 국내 어셈블리 관련 홈페이지
C++ Online Books - C++ 관련 공짜 온라인 북 링크
STL Document - RogueWave Software 의 STL 튜토리얼 및 레퍼런스
Blitz++ - 객체지향 공학용 수치계산 라이브러리(C++)
행렬 라이브러리 비교 - C/C++ 용 행렬 라이브러리 비교평가

GNU/Linux
리눅스사랑넷 - 리눅스사용자라면 꼭 가봐야 할 사이트

KLDP - 리눅스사용자라면 꼭 가봐야 할 사이트
리눅스시스템관리 - 리눅스 시스템 관리자를 위한 홈페이지
Debian-KR 메일링 리스트 - 데비안-KR 메일링 리스트 아카이브
Trinux - 디스켓 3장에 들어가는 리눅스
linux-firewall - linux-firewall
certcc.or.kr - 한국정보보호센터
쉘프로그래밍 - 쉘프로그래밍매뉴얼

SAINT - 보안분석툴
securityfocus.com - 보안관련정보
정규표현식설명 - 정규표현식에 대한 설명
Thinkpad Tool - Thinkpad Notebook Linux Configuration Tool
네트워크프로그래밍 - BeeJ's Guide to Network Programming
webalizer - 웹 로그 분석툴
MRTG - 서버 네트워크 통계 프로그램
VirtualPC - 윈도우에서 리눅스를 깔 수 있다는
IBM Linux - 한국 IBM의 리눅스 기술문서 번역 및 자료
Linux C - Linux C 프로그래밍에 관한
헤커되기 - 헤커가 되는 법(에릭.S.레이몬드)
데비안사용자 - 국내 데비안 사용자 그룹
리눅스 가제트 - 리눅스관련 웹진
프렉 - 헤킹관련 웹진
CygWin - GNU + Cygnus + Windows
GNU GPL FAQ - GPL 에 관련된 빈번한 질문과 답
phpBB - PHP, MySQL 로 만드는 커뮤니티. 디자인이 깔끔.
KTUG - Korea TeX Users Group
KLDP 닷넷 - 소스포지와 같은 국내의 오픈소스 프로젝트 서비스 제공

Emacs
Emacs-KR 홈페이지 - 최고의 에디터인 Emacs 의 사용자 모임

Emacs 설치 - 이맥스 윈도우즈용/유닉스용 설치에 관한...
정재목씨의 Emacs - 정재목씨의 Emacs 관련 페이지
NT Emacs - Windows 95/98/NT 용 Emacs 설명
Elisp Manual - Emacs Lisp Programming
Elisp intro page - Elisp Introduction & link
Elisp Reference - Elisp Reference Manual
VisEmacs - Visual Studio 내장 에디터로 Emacs 를 사용하게 해 줌

개발툴
Doxygen - C++ 개발 문서화 도구

HeaderDoc - C/C++ 헤더파일을 HTML 로 문서화(펄)
CVS Home - 버젼 컨트롤 시스템
RCS - GNU Revision Control System
CS-RCS - 윈도우용 RCS. 1인용은 공짜
ViewCVS - CVS 레파지터리를 웹상에서 보기
ActiveState - ActivePerl, ActiveTCL 등등
Cetus링크 - 프로그래밍관련 방대한 링크
ZipArchive - C++ Zip 압축 라이브러리(소스동봉, zlib 사용)
zlib - zip 라이브러리
Data Compression Lib - 데이터 압축 관련 정보(인덱스, 링크, 소스)
GNU Win32 - Win32 용 각종 GNU 라이브러리 소스(libjpeg, crypt, freetype, zlib 등등)
루아 - 엘레강트하고, 심플하며, 빠르고, 가벼우며, 확장성이 용이한 스크립트 언어
공개 컴파일러들 - 각종 언어에 대한 공개 컴파일러 목록
CGShaders - C for Graphics. 사용자그룹을 가장한 공식홈
UPX - 실행 프로그램 압축 유틸리티. 여러분의 프로그램이 작아집니다.
oggvorbis - 오그 보비스 플러그인, SDK 및 소스 다운로드

MATH
Math Fun Facts - 수학의 재미있는 사실들

AKROWNE's Home - 수학관련 유용한 정보(책 미러 많다)
Math of DFD - Mathematics of DFD(Discrete Fourier Transform)
그리스문자 읽는법 - 그리스 문자를 읽는 방법
Numerican Recipes in C - Numerican Recipes in C 온라인 북
Mech-World - 기계공학관련(동역학,수치해석) 강의노트 및 관련정보
Forgodot - 미적분학 원격 강의
NetLib - 수학관련 문서 및 소프트웨어 모음집
MathBook - Online Books and Lecture Notes in Mathematics
물리의 이해 - 경상대학교의 물리학 노트. 플래쉬 및 자바애플릿.
수학사랑 - 수학교사들의 연구단체
대한 수학회 - 대한민국 수학 학회.
PlanetMath - Wikipedia+MathWorld+Slashdot
MathWorld - 수학 백과 사전. 방대한 자료 상세한 설명.
GIF math - 각종 수학 식에 대한 GIF 이미지 모음

개발자개인홈
Kano - 실시간그래픽스에 관심있는 일본개발자. GPG 일본판 번역자

Ádám Moravánszky - ShaderX 에 Bump Mapped BRDF Rendering 파트집필
Thomas Jakobsen - Game Engine, Physics, Character Animation, Denmark
Pion - 파연님 개인홈. 게임 개발 및 번역.
Cass Everitte - nVidia 사에서 일하는 카스 에버릿. 몇몇 오픈지엘 예제
Hoppe - 메쉬 최적화 및 기타 유용한 자료들. MS 사 댕김.
Newtype - MaxScript, D3D 등등의 여러 개발관련 정보.
Kaliver - 이주형님 개인홈. ASE Viewer 및 Qu Engine

크리에이티브 커먼즈 라이센스
Creative Commons License

쓰레드별 변수 __thread 사용

Posted at 2009/04/09 13:53 // in Programming // by Daniel

OS가 지원해야 하며 일단 제가 알기로는 Linux(2.6부터) gcc와 MSVC에서 지원되는데요,

TLS - Thread Local Storage 라고 불립니다. 시스템콜로 구현되는 것 같더군요.

일단 구현된 내용은 차치하고 사용법은 다음과 같습니다.

 

gcc의 경우만 설명

__thread int my_thread_var;
static __thread int my_static_thread_var;

 

__thread 키워드로 구분되며 이렇게 선언한 변수는 쓰레드마다 가지게 됩니다.

 

관련 내용 링크

Linux 2.6 속으로!

... 또 다른 변화는 TLS (Thread Local Storage) 시스템 호출의 도입이다. 쓰레드 레지스터로 사용될 수 있는 GDT (Global Descriptor Table) 엔트리를 한 개 이상 할당 할 수 있다. GDT는 CPU 기반이고 엔트리는 쓰레드 기반이다.

TLS - Thread Local Storage http://purewell.egloos.com/3398289

* GCC 메뉴얼 보면 TLS가 아니라 TSD(Thread Storage Duration)이라고 표현하였는데 대충 같은 말이다.
이것을 위해 POSIX는 pthread_key_create, pthread_get/setspecific 등 함수를 마련해놨지만 눈만 팽글팽글 돌고, 소스만 지저분해져 보일 것 같다. 귀찮으면 C99, C++98 표준 __thread 키워드를 사용하자.

http://kldp.org/node/78262

~$ /lib/libc.so.6
...
Thread-local storage support included. << 이부분이 보인다면 현재 glibc가 TLS를 지원하는버젼입니다.

크리에이티브 커먼즈 라이센스
Creative Commons License