수안이의 컴퓨터 연구실

  • Mainpage
  • About Me
  • Tags
  • Metapage
  • Notice
  • Location
  • Keywords
  • Guestbook
  • Admin
  • Write an Article
  • Total | 1691993
  • Today | 137
  • Yesterday | 564

4 Articles, Search for 'API'

  1. 2009/09/02 Hadoop 에서 c++ API 이용시 문제점과 해결 방법
  2. 2007/12/24 Google Chart API Article
  3. 2007/12/17 Google Chart API
  4. 2007/05/14 pthread API 레퍼런스 (2)
Framework/Hadoop2009/09/02 14:20

Hadoop 에서 c++ API 이용시 문제점과 해결 방법

기본적으로 Hadoop에서 C++ API 예제를 돌려보려면 다음 사이트를 참고하면 된다.

http://wiki.apache.org/hadoop/C++WordCount

이 에제에서 다음과 같은 명령어를 사용한다.

ant -Dcompile.c++=yes examples



만약 ant 명령어 자체에서 에러가 발생하면, ant를 설치해주어야 한다.

sudo apt-get install ant



그 외에 퍼미션부터 시작해서 애러가 연속해서 일어난다.

more..

Buildfile: build.xml

clover.setup:

clover.info:
     [echo]
     [echo]      Clover not found. Code coverage reports disabled.
     [echo]  

clover:

ivy-download:
      [get] Getting: http://repo2.maven.org/maven2/org/apach ··· -rc2.jar
      [get] To: /usr/local/hadoop/ivy/ivy-2.0.0-rc2.jar
      [get] Not modified - so not downloaded

ivy-init-dirs:

ivy-probe-antlib:

ivy-init-antlib:

ivy-init:
[ivy:configure] :: Ivy 2.0.0-rc2 - 20081028224207 :: http://ant.apache.org/ivy/ ::
:: loading settings :: file = /usr/local/hadoop/ivy/ivysettings.xml

ivy-resolve-common:
[ivy:resolve] :: resolving dependencies :: org.apache.hadoop#Hadoop;working@blade01.kangwon.ac.kr
[ivy:resolve]  confs: [common]
[ivy:resolve]  found commons-logging#commons-logging;1.0.4 in maven2
[ivy:resolve]  found log4j#log4j;1.2.15 in maven2
[ivy:resolve]  found commons-httpclient#commons-httpclient;3.0.1 in maven2
[ivy:resolve]  found commons-codec#commons-codec;1.3 in maven2
[ivy:resolve]  found xmlenc#xmlenc;0.52 in maven2
[ivy:resolve]  found net.java.dev.jets3t#jets3t;0.6.1 in maven2
[ivy:resolve]  found commons-net#commons-net;1.4.1 in maven2
[ivy:resolve]  found org.mortbay.jetty#servlet-api-2.5;6.1.14 in maven2
[ivy:resolve]  found oro#oro;2.0.8 in maven2
[ivy:resolve]  found org.mortbay.jetty#jetty;6.1.14 in maven2
[ivy:resolve]  found org.mortbay.jetty#jetty-util;6.1.14 in maven2
[ivy:resolve]  found tomcat#jasper-runtime;5.5.12 in maven2
[ivy:resolve]  found tomcat#jasper-compiler;5.5.12 in maven2
[ivy:resolve]  found commons-el#commons-el;1.0 in maven2
[ivy:resolve]  found junit#junit;3.8.1 in maven2
[ivy:resolve]  found commons-logging#commons-logging-api;1.0.4 in maven2
[ivy:resolve]  found org.slf4j#slf4j-api;1.4.3 in maven2
[ivy:resolve]  found org.eclipse.jdt#core;3.1.1 in maven2
[ivy:resolve]  found org.slf4j#slf4j-log4j12;1.4.3 in maven2
[ivy:resolve] :: resolution report :: resolve 619ms :: artifacts dl 22ms
 ---------------------------------------------------------------------
 |                  |            modules            ||   artifacts   |
 |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
 ---------------------------------------------------------------------
 |      common      |   19  |   0   |   0   |   0   ||   19  |   0   |
 ---------------------------------------------------------------------

ivy-retrieve-common:
[ivy:retrieve] :: retrieving :: org.apache.hadoop#Hadoop
[ivy:retrieve]  confs: [common]
[ivy:retrieve]  0 artifacts copied, 19 already retrieved (0kB/20ms)
No ivy:settings found for the default reference 'ivy.instance'.  A default instance will be used
DEPRECATED: 'ivy.conf.file' is deprecated, use 'ivy.settings.file' instead
:: loading settings :: file = /usr/local/hadoop/ivy/ivysettings.xml

init:
    [touch] Creating /tmp/null736510671
   [delete] Deleting: /tmp/null736510671
     [exec] src/saveVersion.sh: 34: svn: not found
     [exec] src/saveVersion.sh: 34: svn: not found

record-parser:

compile-rcc-compiler:

compile-core-classes:
    [javac] Compiling 1 source file to /usr/local/hadoop/build/classes

compile-mapred-classes:
    [javac] Compiling 1 source file to /usr/local/hadoop/build/classes

compile-hdfs-classes:
    [javac] Compiling 4 source files to /usr/local/hadoop/build/classes

compile-core-native:

check-c++-makefiles:

create-c++-pipes-makefile:

BUILD FAILED
/usr/local/hadoop/build.xml:1414: Execute failed: java.io.IOException: Cannot run program "/usr/local/hadoop/src/c++/pipes/configure" (in directory "/usr/local/hadoop/build/c++-build/Linux-i386-32/pipes"): java.io.IOException: error=13, Permission denied

Total time: 4 seconds



위와 같은 에러가 발생 할 시 다음과 같은 순서로 해결을 하면 된다.

chmod 755 /usr/local/hadoop/src/c++/pipes/configure

chmod 755 /usr/local/hadoop/src/c++/utils/configure

두 명령어를 통해 퍼미션을 해결하였어도, utils 폴더 내에 컴파일 과정에서 에러가 발생한다면,

wget https://issues.apache.org/jira/secure/attachment/12404588/HADOOP-5611-fixed.patch


위 명령어를 통해 패치를 다운로드 한 뒤,

patch -p0 < HADOOP-5611-fixed.patch


위와 같이 패치를 하고, 다음 명령을 다시 한번 시도한다.

ant -Dcompile.c++=yes examples

"Hadoop" 카테고리의 다른 글
  • Hadoop 에서 c++ API 이용시 문제점과 해결 방법 (0)2009/09/02
  • Ubuntu Linux에서 Hadoop 구축 및 실행 (0)2009/09/02
2009/09/02 14:20 2009/09/02 14:20
Posted by webdizen
Tags API, C++Keyword C++, Hadoop
No Trackback No Comment

Trackback URL : http://www.webdizen.net/blog/trackback/3344

Leave your greetings.

[로그인][오픈아이디란?]

Web2007/12/24 02:35

Google Chart API Article

Google Chart API 관련

Draco Counter 3.0 with Google Chart API

Google Chart API Javascript Wrapper 등장

웹 실시간 차트생성 - 구글 차트 API


Google Chart 자동 생성 툴

http://almaer.com/chartmaker/

http://www.heavytrader.it/google-chart-generator.php

http://charts.hohli.com/


"Web" 카테고리의 다른 글
  • Web Tools의 모든 것 (0)2008/01/23
  • 웹 개발을 하고 있다면 참고할 사이트 (0)2008/01/05
  • Google Chart API Article (0)2007/12/24
  • Google Developer Day US (0)2007/12/18
  • Google Chart API (1)2007/12/17
2007/12/24 02:35 2007/12/24 02:35
Posted by webdizen
Tags API, Chart, Google
No Trackback No Comment

Trackback URL : http://www.webdizen.net/blog/trackback/3158

Leave your greetings.

[로그인][오픈아이디란?]

Web2007/12/17 11:37

Google Chart API

http://code.google.com/apis/chart/

Google의 Chart API를 이용하여 Web 상에서 편리하게 Chart 표현을 할 수 있는 기능이다.
실제 사용해 본 결과 엄청나다. 언제 Google Chart를 이용해서 블로그 방문자 차트나 만들어봐야겠다.

Chart with line in yellow

cht=lc


Line chart with unevenly spaced data points and lines in red, green and dashed blue
cht=lxy
chd=t:0,30,60,70,90,95,100|
20,30,40,50,60,70,80|
10,30,40,45,52|
100,90,40,20,10|
-1|
5,33,50,55,7


Horizontal bar chart with two data sets: one data set is colored in red the second is stacked in green
cht=bhs
chco=ff0000,00aa00


Vertical bar chart with two data sets: one data set is colored in red the second is stacked in green
cht=bvs
chco=cc0000,00aa00


Horizontal bar chart with two data sets: one data set is colored in red the second is adjacent in green
cht=bhg
chco=cc0000,00aa00


Vertical bar chart with two data sets: one data set is colored in red the second is adjacent in green
cht=bvg
chco=cc0000,00aa00


Horizontal bar chart in yellow, bars have the default width
chbh omitted
cht=bhs


Horizontal bar chart in yellow, bars are ten pixels wide
chbh=10
cht=bhs


Two-dimensional pie chart with six segments where segment colors are interpolated from dark to pale orange

cht=p


Three-dimensional pie chart with six segments where segment colors are interpolated from dark to pale orange

cht=p3


Venn diagram with three overlapping circles
cht=v
chd=t:100,80,60,30,30,30,10



Scatter plot with default blue circle data points in different sizes as defined by a third data set
cht=s


Line chart with one red, one blue, and one green line

chco=ff0000,00ff00,0000ff


Line chart with two red lines and one blue line

chco=ff0000,0000ff


Horizontal bar chart with one data set in red the second in green and the third in red

chco=ff0000,00ff00
chd=s:FOE,THE,Bar


Horizontal bar chart with one data set in red, the second stacked in green, and the third in blue

chco=ff0000,00ff00,0000ff
chd=s:FOE,THE,Bar


Three dimensional pie chart with segments interpolated from dark to pale blue

chco=0000ff


Venn diagram with three overlapping circles, one circle is green the others are blue
chco=00ff00,0000ff


Red line chart with pale gray background

chf=bg,s,efefef


Scatter plot with points in blue, chart area in black, and pale gray background

chf=bg,s,efefef|
c,s,000000


Horizontal bar chart with pale yellow background

chf=bg,s,FFF2CC


Red line chart with pale gray background and chart area in a white to blue linear gradient from left to right

chf=
c,lg,0,76A4FB,1,ffffff,0|
bg,s,EFEFEF


Red line chart with pale gray background and chart area in a white to blue diagonal linear gradient from bottom left to top right

chf=
c,lg,45,ffffff,0,76A4FB,0.75|
bg,s,EFEFEF


Red line chart with pale gray background and chart area in a white to blue vertical linear gradient from bottom to top

chf=
c,lg,90,76A4FB,0.5,ffffff,0|
bg,s,EFEFEF


Blue line chart with alternating gray and white stripes from left to right

chf=c,ls,0,CCCCCC,0.2,
FFFFFF,0.2


Blue line chart with a dark gray, pale gray, white and dark gray stripes from bottom to top

chf=
c,ls,90,
999999,0.25,
CCCCCC,0.25,
FFFFFF,0.25


Vertical bar chart with title
chtt=Site+visitors+by+month|
January+to+July


Vertical bar chart with blue, 20 pixel, title
chtt=Site+visitors
chts=FF0000,20


Red, blue, and green line chart with matching legends
chdl=First|Second|Third
chco=ff0000,00ff00,0000ff


Venn diagram with two smaller circles enclosed by a larger circle
chdl=First|Second|Third
chco=ff0000,00ff00,0000ff


Three dimensional pie chart with May, June, July, August, September and October labels for each segment

chl=May|Jun|Jul|Aug|Sep|Oct


Line chart with the labels: 0, 20, 40, 60, 80, and 100 on the left and right and labels: 0, 25, 50, 75, and 100 twice on the x-axis one set below the other

chxt=x,y,r,x,t


Line chart with 0 and 100 on the left, A, B, and C on the right, Jan, July, Jan, July, and Jan on the x-axis and 2005, 2006 and 2007 below

chxt=x,y,r,x
chxl=
0:|Jan|July|Jan|July|Jan|
1:|0|100|
2:|A|B|C|
3:|2005|2006|2007


Line chart with 0 to 100 on the left, A, B, and C on the right, Jan, July, Jan, July, and Jan on the x-axis and 2005, 2006 and 2007 below

chxt=x,y,r,x
chxl=
0:|Jan|July|Jan|July|Jan|

(y-axis omitted)
2:|A|B|C|
3:|2005|2006|2007


Line chart with min, average, and max on the left, 0, 1, 2, and 4 on the right and 0, 25, 50, 75, and 100 along the x-axis
chxt=x,y,r
chxl=1:|min|average|max
chxp=1,10,35,75|2,0,1,2,4


Line chart with 0, 50, 100, 150, and 200 on the left, 1000, 800, 600, 400, 200, and 0 on the right and 250 and 500 on the x-axis
chxt=x,y,r
chxr=0,100,500|1,0,200|2,1000,0


Line chart with 200, 300, and 400 on the x-axis
chxt=x
chxr=0,100,500
chxl=0:|200|300|400
chxp=0,80,300,400


Line chart with min, average, and max on the left, 0, 1, 2, 3, and 4 on the right, 0 to 100 along the x-axis and Jan, Feb, and March in blue below
chxt=x,y,r,x
chxr=2,0,4
chxl=3:|Jan|Feb|Mar|1:|min|average|max
chxp=1,10,35,75
chxs=3,0000dd,13


Line chart with 1st and 15th repeating along the x-axis and Feb and Mar below. All labels are in blue
chxt=x,y,r,x
chxl=3:|Jan|Feb|Mar||
     0:|1st|15th|1st|15th|1st
chxs=0,0000dd,10|3,0000dd,12,1


Line chart with one solid line and one dashed line
chls=3,6,3|1,1,0


Line chart with 5 vertical and two horizontal pale gray dashed grid lines
chg=20,50


Line chart with 5 vertical and two horizontal faint, pale gray, dashed grid lines
chg=20,50,1,5


Line chart with 5 vertical and two horizontal pale gray, solid grid lines
chg=20,50,1,0


Line chart with 20 pixel red cross, 20 pixel green diamond, 9 pixel purple arrow, 20 pixel orange circle, 10 pixel blue square, 1 pixel pale gray vertical line, 1 pixel blue line and a 20 pixel yellow cross all drawn on the data points of a single line. A thin black horizontal line intersects the vertical line v at point 7
chm=
c,FF0000,0,1.0,20.0|
d,80C65A,0,2.0,20.0|
a,990066,0,3.0,9.0|
o,FF9900,0,4.0,20.0|
s,3399CC,0,5.0,10.0|
v,BBCCED,0,6.0,1.0|
V,3399CC,0,7.0,1.0|
x,FFCC33,0,8.0,20.0|
h,3399CC,0,7.0,1.0


Scatter plot with 10 pixel red square markers
chm=
s,FF0000,1,1.0,10.0


Line chart, one line has 10 pixel circles on each data point the other line has 10 pixel diamonds. A circle is drawn on the point that is common to both lines
chm=
o,ff9900,0,1.0,10.0|
o,ff9900,0,2.0,10.0|
o,ff9900,0,3.0,10.0|
d,ff9900,1,1.0,10.0|
d,ff9900,1,2.0,10.0|
d,ff9900,1,3.0,10.0


Line chart with a pale blue horizontal band stretching from 25 percent to 75 percent of the way up the y-axis and a thin horizontal line ten percent of the way up the y-axis
chm=
r,E5ECF9,0,0.75,0.25|
r,000000,0,0.1,0.11


Line chart with a pale blue vertical band stretching from 25 percent to 75 percent of the way along the x-axis and a thin vertical line ten percent of the way along the x-axis
chm=
R,ff0000,0,0.1,0.11|
R,A0BAE9,0,0.75,0.25


Line chart with a pale blue vertical band stretching from 25 percent to 75 percent of the way along the x-axis and a thin vertical line ten percent of the way along the x-axis
chm=
R,ff0000,0,0.1,0.11|
R,A0BAE9,0,0.75,0.25
|
r,E5ECF9,0,0.75,0.25|
r,000000,0,0.1,0.11


Three lines on a chart; chart is shaded in green from bottom to first line, red from first to second line, dark blue from second to third line and pale blue from third line to top of the chart
chd=s:
99,
cefhjkqwrlgYcfgc,

QSSVXXdkfZUMRTUQ,
HJJMOOUbVPKDHKLH,
AA

chm=
b,76A4FB,0,1,0| (light blue)
b,224499,1,2,0| (blue)
b,FF0000,2,3,0| (red)
b,80C65A,3,4,0 (green)

chco=000000,000000,000000,
000000,000000


Three lines on a chart; chart no shading from bottom to first line, red from first to second line, dark blue from second to third line and no shading from third line to top of the chart. Lines are drawn in default yellow
chd=s:
cefhjkqwrlgYcfgc,
QSSVXXdkfZUMRTUQ,
HJJMOOUbVPKDHKLH,

chm=
b,224499,0,1,0| (blue)
b,FF0000,1,2,0| (red)
b,80C65A,2,3,0 (green)


Single line on a chart with shading in blue from the bottom of the chart to the line
chm=B,76A4FB,0,0,0
chd=s:ATSTaVd21981uocA

"Web" 카테고리의 다른 글
  • Google Chart API Article (0)2007/12/24
  • Google Developer Day US (0)2007/12/18
  • Google Chart API (1)2007/12/17
  • 차세대 운영체제 "WebOS" (1)2007/11/08
  • 웹 기반 이미지 편집 툴 "Splashup" (1)2007/11/06
2007/12/17 11:37 2007/12/17 11:37
Posted by webdizen
Tags API, Chart, Google
1 Trackback No Comment

Trackback URL : http://www.webdizen.net/blog/trackback/3153

  1. 속속 공개되는 Google Chart Maker  Delete

    2007/12/21 12:39 Tracked fromPHP와 Web 2.0

    얼마 전 공개 된 구글 Chart API을 사용하여 웹에서 바로 바로 차트를 만들어주는 페이지가 속속 공개되고 있습니다.Chart Maker :http://almaer.com/chartmaker/Google Chart Generator di Luigi Provenza :http://www.heavytr..

Leave your greetings.

[로그인][오픈아이디란?]

Programming/UNIX/Linux C2007/05/14 09:29

pthread API 레퍼런스

출처 : http://teamblog.joinc.co.kr/yundream

pthread API의 레퍼런스 문서이다. 비록 모든 API들에 대한 레퍼런스를 담고 있지않지만, 자주 사용되는 주요 API 들에 대한 레퍼런스에 대한 설명과 예제까지를 포함하고 있다. 몇몇 빠진 API 들은 추후 보강하도록 할것이다.

1절. 소개
2절. 기본 쓰레드 함수
2.1절. pthread_create
2.2절. pthread_join
2.3절. pthread_detach
2.4절. pthread_exit
2.5절. pthread_cleanup_push
2.6절. pthread_cleanup_pop
2.7절. pthread_self
3절. 쓰레드 동기화 함수
3.1절. pthread_mutex_init
3.2절. pthread_mutex_destory
3.3절. pthread_mutex_lock
3.4절. pthread_mutex_unlock
3.5절. pthread_cond_init
3.6절. pthread_cond_signal
3.7절. pthread_cond_boradcast
3.8절. pthread_cond_wait
3.9절. pthread_cond_timewait
3.10절. pthread_cond_destroy
3.11절. 예제코드
4절. Thread Attribute 함수
4.1절. pthread_attr_init
4.2절. pthread_attr_distroy
4.3절. pthread_attr_getscope
4.4절. pthread_attr_setscope
4.5절. pthread_attr_getdetachstate
4.6절. pthread_attr_setdetachstate

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

1절. 소개
이 문서는 pthread 레퍼런스 문서이다. pthread 에서 제공하는 모든 함수의 레퍼런스를 제공하고 있지는 않지만, 자주 쓰일만한 대부분의 함수들은 정리되어 있음으로 참고할만한 가치가 있을것이다.

이 문서에 빠진 내용들은 계속 추가해 나갈 예정이다.


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

2절. 기본 쓰레드 함수
주로 쓰레드 생성과 종료에 관련된 가장 기본적인 함수들이다.


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

2.1절. pthread_create

                       

쓰레드 생성을 위해서 사용한다. 첫번째 아규먼트인 thread 는 쓰레드가 성공적으로 생성되었을때 생성된 쓰레드를 식별하기 위해서 사용되는 쓰레드 식별자이다. 두번째 아규먼트인 attr 은 쓰레드 특성을 지정하기 위해서 사용하며, 기본 쓰레드 특성을 이용하고자 할경우에 NULL 을 사용한다. 3번째 아규먼트인 start_routine는 분기시켜서 실행할 쓰레드 함수이며, 4번째 아규먼는인 arg는 쓰레드 함수의 인자이다.

성공적으로 생성될경우 0을 리턴한다.

예제 : pthread_create.cc

                       

실행된 쓰레드에 대해서는 pthread_join 등의 함수를 이용해서 쓰레드 종료때까지 기다려줘야 한다. ptherad_join 은 일종의 fork 의 wait 와 비슷하게 작동하며, 쓰레드자원을 해제 시켜준다.


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

2.2절. pthread_join

                       

첫번째 아규먼트 th는 기다릴(join)할 쓰레드 식별자이며, 두번째 아규먼트 thread_return은 쓰레드의 리턴(return) 값이다. thread_return 이 NULL 이 아닐경우 해다 포인터로 쓰레드 리턴 값을 받아올수 있다.

pthread_joinc.c




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

2.3절. pthread_detach

                       

detach 는 "떼어내다" 라는 뜻을 가지며 main 쓰레드에서 pthread_create 를 이용해 생성된 쓰레드를 분리시킨다. 이 함수는 식별번호th인 쓰레드를 detach 시키는데, detach 되었을경우 해당(detach 된) 쓰레드가 종료될경우 pthread_joinc 을 호출하지 않더라도 즉시 모든 자원이 해제(free) 된다.

여기에서는 pthread_create 호출후 detach 하는 방법을 설명하고 있는데, pthread_create 호출시에 쓰레드가 detach 되도록 할수도 있다. 이에 대한 내용은 pthread_attr_setdetachstate 를 다루면서 설명하도록 하겠다.

예제 : pthread_detach.c

                       

위의 쏘쓰 코드에서 detach 시켰을때와 그렇지 않았을때의 메모리 상황을 비교해보기 바란다. detatach 를 했을경우 프로세스의 메모리 사용율과 detache 를 주석 처리했을경우의 메모리 사용율의 변화를 서로 비교해보면 되는데, detach 를 사용하지 않았을경우 t_function 이 종료가 되더라도 자원이 해제되지 않음을 볼수 있을것이다. 테스트는 간단한 스크립트를 이용하도록 한다.
[root@localhost test]# while [ 1 ]; do ps -aux | grep pthread | grep -v grep | grep -v vim; sleep 1; done
root      2668  0.0  0.1  1436  292 pts/8    S    18:37   0:00 ./pthread_detach
root      2668  0.0  0.1  1436  292 pts/8    S    18:37   0:00 ./pthread_detach
                       

위의 ps 내용에서 5번째 필드의 변화를 확인하면 된다.


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

2.4절. pthread_exit

                       

pthread_exit 는 현재 실행중인 쓰레드를 종료시키고자 할때 사용한다. 만약 pthread_cleanup_push 가 정의되어 있다면, pthread_exit 가 호출될경우 cleanup handler 가 호출된다. 보통 이 cleanup handler 은 메모리를 정리하는 등의 일을 하게 된다.

예제 : pthread_exit.c




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

2.5절. pthread_cleanup_push



이것은 cleanup handlers 를 인스톨하기 위해서 사용된다. pthread_exit(3) 가 호출되어서 쓰레드가 종료될때 pthread_cleanup_push 에 의해서 인스톨된 함수가 호출된다. routine이 쓰레드가 종료될때 호출되는 함수이다. arg는 아규먼트이다.

cleanup handlers 는 주로 자원을 되돌려주거나, mutex 잠금등의 해제를 위한 용도로 사용된다. 만약 mutex 영역에서 pthread_exit 가 호출되어 버릴경우 다른쓰레드에서 영원히 block 될수 있기 때문이다. 또한 malloc 으로 할당받은 메모리, 열린 파일지정자를 닫기 위해서도 사용한다.

예제 : pthread_cleanup.c




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

2.6절. pthread_cleanup_pop
pthread_cleanup_push 와 함께 사용되며, install 된 cleanup handler 을 제거하기 위해서 사용된다.

                       

만약 execute 가 0 이라면, pthread_cleanup_push 에 의해 인스톨된 cleanup handler 를 (실행시키지 않고)삭제만 시킨다. 0 이 아닌 숫자라면 cleanup handler 을 실행시키고 삭제 된다. 사용예제는 2.5절을 참고하라.

그리고 pthread_cleanup_push 와 pthread_cleanup_pop 은 반드시 같은 함수내의 같은 레벨의 블럭에서 한쌍으로 사용해야 한다.


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

2.7절. pthread_self

                       

pthread_self를 호출하는 현재 쓰래드의 쓰레드식별자를 되돌려준다.

예제 : pthread_self.c




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

3절. 쓰레드 동기화 함수
쓰레드 동기화와 관련된 함수들이다.


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

3.1절. pthread_mutex_init

                       

mutex 는 여러개의 쓰레드가 공유하는 데이타를 보호하기 위해서 사용되는 도구로써, 보호하고자 하는 데이타를 다루는 코드영역을 단지 한번에 하나의 쓰레드만 실행가능 하도록 하는 방법으로 공유되는 데이타를 보호한다. 이러한 코드영역(하나의 쓰레드만 점유가능한)을 critical section 이라고 하며, mutex 관련 API 를 이용해서 관리할수 있다.

pthread_mutex_init 는 mutex 객체를 초기화 시키기 위해서 사용한다. 첫번째 인자로 주어지는 mutex 객체 mutex를 초기화시키며, 두번째 인자인 attr 를 이용해서 mutex 특성을 변경할수 있다. 기본 mutex 특성을 이용하기 원한다면 NULL 을 사용하면 된다.

mutex 특성(종류) 에는 "fast", "recurisev", "error checking" 의 종류가 있으며, 기본으로 "fast" 가 사용된다.





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

3.2절. pthread_mutex_destory

                       

인자로 주어진 뮤텍스 객체 mutex 를 제거하기 위해서 사용된다. mutex 는 pthread_mutex_init()함수를 이용해서 생성된 뮤텍스 객체이다.

pthread_mutex_destory 를 이용해서 제대로 mutex 를 삭제하려면 이 mutex 는 반드시 unlock 상태이여야 한다.


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

3.3절. pthread_mutex_lock

                       

pthread_mutex_lock 는 critcal section 에 들어가기 위해서 mutex lock 을 요청한다. 만약 이미 다른 쓰레드에서 mutex lock 를 얻어서 사용하고 있다면 다른 쓰레드에서 mutex lock(뮤텍스 잠금) 을 해제할때까지(사용할수 있을때까지) 블럭 된다.

만약 다른 어떤 쓰레드에서도 mutex lock 을 사용하고 있지 않다면, 즉시 mutex lock 을 얻을수 있게 되고 critcal section 에 진입하게 된다. critcal section 에서의 모든 작업을 마쳐서 사용하고 있는 mutex lock 이 더이상 필요 없다면 pthread_mutex_unlock 를 호출해서 mtuex lock 를 되돌려준다.


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

3.4절. pthread_mutex_unlock

                       

critical section 에서의 모든 작업을 마치고 mutex lock 을 돌려주기 위해서 사용한다. pthread_mutex_unlock 를 이용해서 mutex lock 를 되돌려주면 다른 쓰레드에서 mutex lock 를 얻을수 있는 상태가 된다.


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

3.5절. pthread_cond_init

                       

pthread_cond_init는 조견변수 (condition variable)cond를 초기화하기 위해서 사용한다. attr 를 이용해서 조건변수의 특성을 변경할수 있으며, NULL 을 줄경우 기본특성으로 초기화된다.

조건변수 cond는 상수 PTHREAD_COND_INITIALIZER 을 이용해서도 초기화 할수 있다. 즉 다음과 같은 2가지 초기화 방법이 존재한다.
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
or
pthread_cond_init(&cond, NULL);
                       




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

3.6절. pthread_cond_signal

                       

조건변수 cond에 시그날을 보낸다. 시그날을 보낼경우 cond에서 기다리는(wait) 쓰레드가 있다면 쓰레드를 깨우게 된다(봉쇄가 풀림). 만약 조건변수 cond를 기다리는 쓰레드가 없다면, 아무런 일도 일어나지 않게되며, 여러개의 쓰레드가 기다리고 있다면 그중 하나의 쓰레드에게만 전달된다. 이때 어떤 쓰레드에게 신호가 전달될지는 알수 없다.


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

3.7절. pthread_cond_boradcast

                       

조건변수 cond에서 기다리는(wait) 모든 쓰레드에게 신호를 보내서, 깨운다는 점을 제외하고는 pthread_cond_signal과 동일하게 작동한다.


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

3.8절. pthread_cond_wait
                       

조건변수 cond를 통해서 신호가 전달될때까지 블럭된다. 만약 신호가 전달되지 않는다면 영원히 블럭될수도 있다. pthread_cond_wait는 블럭되기 전에 mutex 잠금을 자동으로 되돌려준다.


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

3.9절. pthread_cond_timewait

                       

조건변수 cond를 통해서 신호가 전달될때까지 블럭되며 자동으로 mutex을 돌려주는 점에서는 pthread_cond_wait와 동일하다. 그러나 시간체크가 가능해서 abstime시간동안 신호가 도착하지 않는다면 error 를 발생하면서 리턴한다. 이때 리턴값은 ETIMEDOUT 이다. errno 가 세팅되는게 아닌, 리턴값으로 에러가 넘어오는것에 주의해야 한다.

또한 pthread_cond_timedwait함수는 다른 signal 에 의해서 interrupted 될수 있으며 이때 EINTR 을 리턴한다. 이 함수를 쓸때는 interrupted 상황에 대한 처리를 해주어야 한다.


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

3.10절. pthread_cond_destroy

                       

pthread_cond_init를 통해서 생성한 조건변수cond에 대한 자원을 해제한다. destroy 함수를 호출하기 전에 어떤 쓰레드도 cond에서의 시그널을 기다리지 않는걸 확인해야 한다. 만약 cond 시그널을 기다리는 쓰레드가 존재한다면 이 함수는 실패하고 EBUSY 를 리턴한다.


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

3.11절. 예제코드
이번장에서 설명한 쓰레드 동기화 관련 함수의 이해를 돕기 위해서 간단한 예제를 준비했다. 설명은 주석으로 대신한다.

예제 : pthrad_sync_api.c
                       



위의 예제는 ping&pong 프로그램으로 ping 쓰레드와 pong 쓰레드가 각각 번갈아가면서 "ping", "pong" 을 날리는 프로그램이다. 2개의 영역에 걸쳐서 크리티컬섹션이 지정되어 있으며 각 크리티컬섹션안에는 쓰레드 동기화를 위해서 ptread_cond_signal 이 쓰여지고 있다.

위의 코드는 기본적으로 pong 쓰레드가 먼저 시그널을 대기하고 있다가 그 후 ping 쓰레드가 진입해서 "ping"을 날리고 시그널을 발생시키면 "pong" 메시지를 발생시키도록 되어 있다. 그렇다면 while 문에 있는 크리티컬 섹션에 반드시 pong 쓰레드가 먼저 진입할수 있도록 만들어줘야 할것이다. 그래서 위의 코드에서는 pong 쓰레드를 먼저 생성시켰다. 그러나 이것만으로는 충분하지 않다. 예를들어서 pong 쓰레드에서 크리티컬섹션에 들어가기 위해서 어떤 부가적인 작업이 있다고 했을때(메모리초기화, 기타 다른 함수 호출과 같은, 위에서는 sleep 으로 대신했다), 우리가 의도했던 바와는 다르게 ping 가 먼저 크리티컬섹션에 진입할수도 있다. 이럴경우 2개의 쓰레드는 교착상태에 빠지게 된다.

ping 쓰레드가 크리티컬섹션에 먼저 진입했을경우 ping 쓰레드는 "ping" 출력시키고 시그널을 발생시킬 것이고 pong 쓰레드가 "pong"를 출력시키고 시그널을 발생시킬때까지 시그널대기 하게 된다. ping 쓰레드가 시그널대기 하게 되면, 크리티컬섹션에 대한 뮤텍스 잠금이 해제됨으로 뒤늦게 크리티컬섹셔네 진입을 시도하던 pong 가 크리티컬섹션에 진입하고 ping 쓰레드에서부터 신호가 있는지 기다리게 될것이다. 그러나 ping 쓰레드는 이미 신호를 날려버렸음으로, pong 쓰레드는 결코 도착하지 않을 신호를 기다리며 영원히 시그널대기 하게 될것이다. 이런식으로 2개의 쓰레드는 교착상태에 빠져 버린다.

이 문제는 쓰레드간 동기화를 이용해서 해결할수 있으며, 위 코드에서는 mutex 잠금과, 조건변수를 이용해서 해결하고 있다. 물론 쓰레드간 동기화를 위해서 사용할수 있는 원시?적인 방법으로 sleep 나 usleep 같은 함수를 호출하는 방법도 있긴 하지만, ping 쓰레드에서 크리티컬 섹션에 진입하기전 1초 정도 sleep 을 주는 식으로 사용가능하지만 추천할만하진 않다. (간혹 간단하게 사용할수는 으며, 가장 확실한 방법을 제공해 주기도 한다)


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

4절. Thread Attribute 함수
4.1절. pthread_attr_init


                       

pthread_attr_init는 thread attribute 객체인 attr을 디폴트 값으로 초기화 시킨다.

성공할경우 0을 돌려주고 실패할경우 -1 을 되돌려준다.


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

4.2절. pthread_attr_distroy

                       

pthread_attr_init에 의해 생성된 thread attribute 객체인 attr을 제거한다. 제거된 attr 을 다시 사용하기 위해서는 pthread_attr_init를 이용해서 다시 초기화 해주어야 한다.


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

4.3절. pthread_attr_getscope

                       

쓰레드가 어떤 영역(scope)에서 다루어지고 있는지를 얻어오기 위해서 사용된다. PTHREAD_SCOPE_SYSTEM과 PTHREAD_SCOPE_PROCESS 의 2가지 영역중에 선택할수 있다. SYSTEM 영역 쓰레드는 user 모드 쓰레드라고 불리우며, PROCESS 쓰레드는 커널모드 쓰레드라고 불리운다. 리눅스의 경우 유저모드 쓰레드인데, 즉 커널에서 쓰레드를 스케쥴링하는 방식이 아닌 쓰레드 라이브러리를 통해서 쓰레드를 스케쥴링 하는 방식을 사용한다.


                       

위 프로그램을 컴파일한후 Linux 에서 실행시키면 "user mode thread"를 출력하고 솔라리스 상에서 실행시키면 "kernel mode thread"를 출력한다.


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

4.4절. pthread_attr_setscope

                       

쓰레드가 어떤 영역(scope)에서 작동하게 할것인지 결정하기 위해서 사용한다. 리눅스의 경우 Kernel mode 쓰레드를 지원하지 않음으로 오직 PTHREAD_SCOPE_SYSTEM 만을 선택할수 있다. 반면 솔라리스는 유저모드와 커널모드중 선택이 가능하다.

pthread_attr_setscope.c

                       

위코드에서 쓰레드가 커널 모드에서 작동하도록 지정을 했다. 리눅스에서 실행시킬경우에는 비록 커널모드로 지정을 했다고 하더라도 유저모드 쓰레드로 작동하게 된다. 솔라리스의 경우에는 setscope 로 지정한대로 커널모드에서 작동하게 된다.


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

4.5절. pthread_attr_getdetachstate

                       

쓰레드가 join 가능한 상태(PTHREAD_CREATE_JOINABLE) 인지 detached 상태인지 (PTHREAD_CREATE_DETACHED) 인지를 알아낸다. 알아낸 값은 아규먼트 detachstate 에 저장된다.

기본은 PTHREAD_CREATE_JOINABLE 이며, pthread_detach를 이용해서 생성된 쓰레드를 detach 상태로 만들었을경우 또는 pthread_attr_setdetachstate함수를 이용해서 쓰레드를 detache 상태로 변경시켰을경우 PTHREAD_CREATE_DETACHED 상태가 된다.

예제 : pthread_attr_getdetachstate.c

                       

위의 프로그램을 실행시키면 분명 "Join able"를 출력할것이다.


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

4.6절. pthread_attr_setdetachstate

                       

쓰레드의 상태를 PTHREAD_CREATE_JOINABLE 혹은 PTHREAD_CREATE_DETACHED 상태로 변경시키기 위해서 사용된다. 아래와 같은 방법으로 사용하면 된다.

"UNIX/Linux C" 카테고리의 다른 글
  • random 값 얻어오기 (0)2007/05/14
  • openssl 을 통한 데이타 암호화 (0)2007/05/14
  • pthread API 레퍼런스 (3)2007/05/14
  • 안전한 프로그래밍 (0)2007/05/11
  • 쓰레드와 시그널 (0)2007/05/11
2007/05/14 09:29 2007/05/14 09:29
Posted by webdizen
Tags API, pthread, Thread, 레퍼런스
1 Trackback 2 Comments

Trackback URL : http://www.webdizen.net/blog/trackback/2931

  1. Pthread 채널  Delete

    2007/05/30 10:32 Tracked from

    Pthread와 관련된 내용들을 다루는 채널입니다.트랙백 주소는 http://teamblog.joinc.co.kr/Cpthread/trackback/1 입니다.카테고리 페이지로 바로가기

Leave your greetings.

  1. yundream

    쓰레드 관련 글을 찾다가 들어왔습니다.
    예전에 제가 작성한 글이군요.
    쓰레드와 관련되어서 몇개 참고할만한 글들이 더 있어서 트랙백겁니다.

    쓰레드와 관련된 많은 정보교환 부탁드립니다. 그럼 오늘도 좋은 하루 되세요.

    2007/05/30 10:34 [ Permalink : Modify/Delete : Reply ]
  2. webdizen

    안녕하세요.
    저도 joinc가 아닌 다른 곳에서 정보를 얻었는지라...
    지금보니 출처 표시를 미처 하지 못했었네요. 죄송합니다.

    해당 주소로 출처 표시 하겠습니다.

    2007/05/31 10:41 [ Permalink : Modify/Delete : Reply ]
[로그인][오픈아이디란?]

«Prev  1  Next»

RSS HanRSS
Blog Image
webdizen
이곳은 컴퓨터에 대해 연구하고, 공유하고, 소통하기 위한 연구실입니다. 개인적으로는 OLAP, Data Mining, Semantic Web, Data Modeling에 대해서 연구하고 있습니다.

Categories

전체 (3009)
Webdizen (141)
Life (6)
Diary (16)
Blog (9)
IDEA (2)
Travel (10)
Book (16)
Photo (7)
Movie (8)
Music (14)
Leisure Sports (10)
Funny (6)
Hardware (121)
Software (120)
Windows (5)
Unix & Linux (120)
Installation (5)
Kernel (10)
System (34)
Develop (22)
X-Window (0)
Applicaton (31)
Security (4)
Framework (2)
Hadoop (2)
Programming (804)
Algorithm & Data Structure (1)
Assembly (38)
UNIX/Linux C (95)
C++ (128)
STL (4)
Java (38)
Win32 API (92)
ATL/COM (44)
MFC (151)
.NET (26)
WCF/WPF (4)
C# (28)
Network Programming (17)
Database Programming (12)
OpenGL / DirectX (13)
Multimedia Programming (0)
Game Programming (21)
Parallel Distributed Progra... (0)
Reverse Engineering (0)
Debugging (9)
Python (1)
Ruby (1)
Ruby on Rails (1)
QT (4)
GTK (0)
JSP (0)
PHP (6)
ASP.NET (6)
ASP (2)
Development (28)
Useful Library (2)
Data Modeling (0)
Database (105)
Oracle (4)
MSSQL (41)
MySQL (2)
Data Warehouse (2)
Data Mining (4)
Network (66)
Web (79)
DHTML (4)
XHTML (1)
Javascript (1)
CSS (1)
AJAX (9)
XML (11)
Flex (1)
Silverlight (3)
Security (91)
DoS (1)
Kernel (10)
Scanning (3)
Sniffing (0)
Spoofing (4)
Overflow (28)
Web (11)
Shell (10)
Format String (14)
Window (2)
Embedded (70)
Multimedia (27)
Mobile (14)
Graphic (24)
Management (633)
Knowledge (581)
Hadoop (0)

Notice

  • 메타 블로그 사이트에 등록
  • 새해 맞이 블로그의 변화
  • 블로그 명칭 변경
  • 도메인(www.webdizen.net) 구...
  • TEXTCUBE 1.6.1로 업그레이드...

Tags

  • 건축물
  • 커널 디버깅
  • Ultimate OSX
  • 쓰레드
  • 바탕화면
  • 강원대학 교기
  • KLM
  • 모형 만들기
  • 의과대학
  • openssl
  • 유럽
  • WORLDCOMP
  • BOM
  • SQL 주입
  • 고급 명령
  • 구글
  • Travel
  • SystemTray
  • Templates
  • 제1기숙사

Recent Articles

  • 트위터(Twitter)의 시작!.
  • 청년 리더의 조건.
  • 애플의 타블렛 PC - 아이패드....
  • 미래의 인터페이스 - 육감 기....
  • 기초발성법 동영상 강좌.

Recent Comments

  • 학교 과제물중 쓰레드에 대하....
    장진혁 03/17
  • 관리자만 볼 수 있는 댓글입....
    비밀방문자 03/12
  • 상대방의 이야기를 열심히 경....
    DoNuts 03/03
  • Lots of students know techn....
    Bobbi35Shannon 02/25
  • 좋은글 잘 보고 갑니다..
    Und_hacker 01/08

Recent Trackbacks

  • printf,scanf를 이용한 형식....
    yundream의 프로그래밍 이야기 03/10
  • 파일 열기/저장하기 CFileDialog.
    은마군의 나태블록 2009
  • World IT Show 2008.
    상우 :: Oranzie's BLOG 2008
  • cvs서버 설치하기.
    3인3색 2008
  • 속속 공개되는 Google Chart....
    PHP와 Web 2.0 2007

Archive

  • 2010/02 (1)
  • 2010/01 (6)
  • 2009/12 (5)
  • 2009/09 (3)
  • 2009/08 (1)

Calendar

«   2010/03   »
일 월 화 수 목 금 토
  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 27
28 29 30 31      

Bookmarks

    • Administration
      • IIS.NET
      • NTFAQ
      • OS의 모든 것
      • 리눅스포털
    • Database
      • SQL Server Central
      • SQL Team
    • Development
      • .NET Heaven
      • ASP Alliance
      • ASP.NET 2.0
      • Bullog.net
      • C# Corner
      • C++ (C PlusPlus.com)
      • C++ Reference
      • CodeGuru
      • CodePlex
      • DebugLab
      • Dev Articles
      • Devpia
      • DotNet Junkies
      • DotNet Zone
      • Driver Online
      • GOSU.NET
      • HOONS 닷넷
      • Joinc 팀블로그
      • KOSR
      • MSDN Home Page
      • OSR Online
      • Sky.ph - 개발자 커뮤니...
      • TAEYO.NET
      • The Code Project
      • WindowsClient.net
      • 김상욱의 개발자 Side
      • 조인시 위키
    • Human Networks
      • belief21c's e-space
      • I think I can
      • Invisible Rover's Blog :D
      • Rodman®
      • ■ Feel So Good~! ■
      • 까만 나비
      • 나를 가꾸는 시간.
      • 나만의 즐거움~~!
      • 단녕
      • 상우 :: Oranzie's BLOG
    • Information Technology
      • Microsoft TechNet
      • 지디넷코리아 - 글로벌...
    • Security
      • FoundStone
      • milw0rm
      • NewOrder
      • OpenRCE
      • Phrack.org
      • Reverse Engineering b1...
      • Reverse Engineering Team
      • RootKit
      • SecurityFocus
      • SecurityXploded by Nag...
      • Wow Hacker
      • Zone-H
Textcube
Louice Studio Inc.
Powered by Textcube. Original designed by Tistory.