errno 의 thread-safe

ddoman의 이미지

errno 값도 thread-safe 하나요?
만약 그렇지 않다면 thread 환경에서 errno 체크를 통한 에러처리를
어떻게 해야할까요?

물어본김에...윈도우쪽 얘길 듣자니( 잘 모름 ) thread-safe한 libc와
safe하지 않은 libc가 따로 있어서, 프로젝트 옵션에서 어느것을 링크할것인지
정해준다고 들었는데,
리눅스에 들어 있는 glibc는 thread-safe한가요?
그리고 수많은 시스템콜들도 thread-safe한가요?
특별히 thread-safe하지 않은 함수면 man 페이지에 명시가 되어있나요?

너무 질문만 많은것 같군요.. :D
이래저래 궁금한게 많습니다. 속 시원히 알려주시면 감사하겠습니다.

bw001730의 이미지

REENTRANT라고 들어보셨죠?
이게..errno를 스레드 safe하게 한답니다.
원래 errno는 전역변수이지만..
REENTRANT선언하면
헤더파일보니깐...
errno가 변수가 아닌..요상한? 매크로가 되더군요
암튼 reentrant선언하시면 되구요
다만 이때 성능의 저하가 약간 있다고 하더군요

thread-safe하지 않은 것은
요걸 사용하라고 맨페이지에 나옵니다.

글구 return값이 0이면 성공이고 0이 아니면 실패인 함수들은
내가 아는 범위내에서는 전부 thread-safe 한것같구요

책에보니깐...함수설계시 errno를 사용하지 말구
참이면 0을 리턴하게.. 실패하면 errno값을 리턴하게 만들라고
권고하더군요 그러면 errno를 사용할 필요가 없잔아요
이상입니다.

ifyou의 이미지

질문보고 저도 궁금해 졌는데..

혹시나 싶어 man errno 라고 쳐 보니까 나오네요

윗분말씀처럼 thread-safe합니다.

nTachyon의 이미지

컴파일 하실때 이 심볼 정의해서 컴파일 하세요

-DREENTRANT

그럼 각 스레드마다 자신의 errno 을 가집니다

ddoman의 이미지

nTachyon wrote:
컴파일 하실때 이 심볼 정의해서 컴파일 하세요

-DREENTRANT

그럼 각 스레드마다 자신의 errno 을 가집니다

/usr/include 에서 grep해보니 나오는건 REENTRANT 가 아니라
_REENTRANT 이던데요?

뭘 define 해야하는건가요?

nTachyon의 이미지

_REENTRANT 맞습니다 ^^

Quote:
뭘 define 해야하는건가요?

gcc -D_REENTRANT -o program source.c

라고 컴파일시에 _REENTRANT 심볼을 define 해주시면 된다는 얘깁니다.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.