pthread_mutex_t.__data.__owner 값과 pthread_self() 그리고 gettid()

assert의 이미지

안녕하세요. 눈팅만 하다가 글 남겨봅니다.

pthread_mutex_t를 비롯한 각종 pthread 자료구조의 내부 필드를 접근할 필요가 있게 되었습니다. 물론 이들 자료구조들은 프로그래머가 그 내부 모양을 모르고 사용하도록 의도된 것임을 잘 알고 있습니다.

제가 사용중인 개발 머신에서 pthread_mutex_t는 /usr/include/bits/pthreadtypes.h 에 선언되어 있고, 여기에서 제가 참조하고 싶은 필드는 아래와 같습니다.
pthread_mutex_t.__data.__owner
pthread_mutex_t.__data.__count
pthread_mutex_t.__data.__kind
(위 필드들을 억세스하는 행위의 위험성에 대해서도 잘 인지하고 있습니다)

위 필드 중에서 __owner 필드는 mutex를 소유하고 있는 (해당 mutex가 잠겨있다면 마지막으로 잠근) thread를 식별하는 값입니다. 이 값은 pthread_self() 가 반환하는 값과는 다른 값입니다. glibc 소스코드를 확인해보면 __owner 필드의 값은 thread control block 의 tid 값임을 추측할 수 있으나 pthread_self() 가 반환하는 값은 tcb의 주소를 pthread_t 타입으로 캐스팅한 값이지요.

일반적으로 쓰레드를 고유하게 식별하는 값을 얻기 위해서는 pthread_self() 를 쓸 수 있지만, mutex의 __owner 필드에서 사용되는 형식의 식별자를 얻을 수 있는 방법은 없는 것일까요?

이리저리 고민하다, gettid() 를 사용해보았습니다. syscall(__NR_gettid) 로 호출 가능한 이 함수는 그 내부가 어떻게 구현되어 있는지 확인하지는 않았지만, mutex의 __owner 필드의 값과 일치하더군요. 뭐 대충 문제는 해결할 수 있을 것 같긴한데, 깨름직합니다.

pthread_mutex_t.__data.__owner 에 사용되는 형식의 스레드 식별자를 얻을 수 있는 보다 안전하고 쓸만한 방법이 있을까요?

조언 부탁드립니다.

댓글 달기

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