2013년 10월 1일 화요일

쓰레드에 arg인자 받을때warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

sol:

 pthread_create(&func_node_thread, NULL, NodeInfoThread, (void*)Socket);


 void    *NodeInfoThread(void *_sock) {

         int sock = *(int *)_sock;


       

        int sock = (int) ((void*) _sock); <- 컴파일시 오류는 안나지만 원하는 결과를 못얻는다.. 주의

C표준은  int를 void*로 또는 그 반대로 캐스팅을 때의 결과를 정의하지 않았다. 하지만 대부분의 C 컴파일러는 이런동작을 허용하고 원하는 결과를 내놓는다.

2013년 9월 15일 일요일

multithread good example(link)

http://mmanoba.wordpress.com/2011/07/18/c-program-linux-posix-multithread-multitasking-example/

2013년 9월 12일 목요일

linux- eclipse 에서 thread 컴파일 안될때

right click on the project in the project explorer
-> properties
-> c/c++ build
-> Settings
-> linker
-> libraries
-> add
 -> pthread
-> ok

-> rebuild

path는 안잡아줘도 되더이다. 만약에 아규먼트 error가나면 (pthread_create invalid arguments...) 가 뜬다면 이것은 이클립스 문제가 아니라. 코드문제!! 다른부분들을 예제에 맞추어 잘했다면.. 오류가 나지 않겠지만 위와같은경우 대부분 마지막 파라미터값이 문제가된다. thread로 사용할 함수의 인자를 아래와 같이
비어두게되면 error가난다. void* thread(void*) 와 같이 파라미터를 명시해주어야 한다.!!

2013년 9월 4일 수요일

유닉스/리눅스 시스템 프로세스(process) 메모리 배치

간단히 프로세스(process)는 실행중인 프로그램이다.

프로세스는 논리적으로 다음과 같은 세그먼트(segment)로 나뉜다.


-text:프로그램의 명령

-data:프로그램이 사용하는 정적(static) 변수

-heap: 프로그램이 실행 중에 추가로 메모리를 할당할 수 있는 영역

-stack: 함수가 호출되고 리턴됨에 따라 자라고 줄어드는 메모리 영역으로,
지역 변수와 함수 호출 연결 정보가 저장된다.