POSIX thread에서

antistar의 이미지

pthread_attr_setstacksize 함수를 이용하면 default 값보다 큰 값에서 조절이 가능하다고
책에 쓰여 있는데, 그럼 default 값보다 적게 적용하려면 어떤 방법이 있을까요?

IsExist의 이미지

pthread_attr_getstacksize 함수를 이용해서 디폴트 값을 얻어 내고
그 값보다 작은 값으로 pthread_attr_setstacksize 함수를 호출하세요.
---------
간디가 말한 우리를 파괴시키는 7가지 요소

첫째, 노동 없는 부(富)/둘째, 양심 없는 쾌락
셋째, 인격 없는 지! 식/넷째, 윤리 없는 비지니스

이익추구를 위해서라면..

다섯째, 인성(人性)없는 과학
여섯째, 희생 없는 종교/일곱째, 신념 없는 정치

---------
간디가 말한 우리를 파괴시키는 7가지 요소

첫째, 노동 없는 부(富)/둘째, 양심 없는 쾌락
셋째, 인격 없는 지! 식/넷째, 윤리 없는 비지니스

이익추구를 위해서라면..

다섯째, 인성(人性)없는 과학
여섯째, 희생 없는 종교/일곱째, 신념 없는 정치

antistar의 이미지

그런데 위와 같이
pthread_attr_getstacksize 함수를 이용해서 디폴트 값을 얻어 내고
그 값보다 작은 값으로 pthread_attr_setstacksize 함수를 호출하였는데

thread create error!!(12)
error : (Cannot allocate memory)

이와 같은 에러가 발생합니다.

디폴트 값은 stack size : 10485760 이고
다시 셋한 값은 stack size : 51200 으로 나왔습니다.

이 함수를 적용하지 않고

ulimit -s 50 으로 하였을 경우에는 문제 없이 잘 되었습니다.
코드 상의 문제일까요?

result = pthread_attr_getstacksize ( &pFssInfo->threadInfo[threadNo].thAttr, &stack );
356 if ( status < 0)
357 {
358 posLogPrint ( "wap thread attr wrong stack size\n");
359 return RE_ERR;
360 }
361 printf ( "stack size : %d\n", stack );
362
363 stack = 50 * 1024;
364 #if 1
365 result = pthread_attr_setstacksize ( &pFssInfo->threadInfo[threadNo].thAttr, &stack );
366 if ( status < 0)
367 {
368 posLogPrint ( "wap thread attr wrong stack size\n");
369 return RE_ERR;
370 }

에고 계속 막히니까 미치겠네요 ㅠㅠ

mg2000의 이미지

혹시 joinable로 thread생성하시고, thread_join으로 종료를 안 시키신 것 아닌지요?

thread를 detachable로 생성하면, thread종료시에 자동으로 리소스를 해제하기 때문에, 문제가

해결 되는 것 같습니다.

thread개수가 초과된 문제라면, 12번 에러가 아니라 다른 에러 번호가 나오는 걸로 알고 있거든요.

antistar의 이미지

pthread_attr_setdetachstate ( &pFssInfo->threadInfo[threadNo].thAttr,
PTHREAD_CREATE_DETACHED );
if ( status != 0)
{
posLogPrint ( "thread setdetachstate fail\n");
return RE_ERR;
}
그래서 다음과 같이 추가하였는데 아직도 같은 에러가 발생합니다.
thread는 무한 루프를 돌고 에러 발생시 빠져나와서 종료하는 형식으로 짰습니다.
thread_exit은 사용하지 않았습니다.

mg2000의 이미지

thAttr을 pthread_create의 argument로 넘기셨겠죠?

antistar의 이미지


result = pthread_create ( &pFssInfo->threadInfo[threadNo].pthreadId,
&pFssInfo->threadInfo[threadNo].thAttr, fssWapRecv,
(void *)threadNo);
if ( result != 0 )
{
posLogPrint ( "thread create error!!(%d)\n", result );
posLogPrint ( " error : (%s)\n", strerror(result) );
return RE_ERR;
}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.