thread와 signal handler에 관한 질문입니다.

kuaaan의 이미지

오랜만에 질문을 올리네요.
http://pauillac.inria.fr/~xleroy/linuxthreads/faq.html
을 읽다가 의문이 생겨 질문합니다.

Quote:
Notice that all pthread_* functions are not async-signal safe, meaning that you should not call them from signal handlers. This recommendation is not to be taken lightly: your program can deadlock if you call a pthread_* function from a signal handler!

말하자면... signal handler에서 pthread_mutex_lock()같은 함수를 사용하지 말라는 뜻인데요...
저는 지금 쓰고 있거든요... ㅡ.ㅜ
왜 쓰지 말라고 하는건지 궁금합니다.

아마도 제 생각에는... signal 하나를 처리하고 있는 동안 이미 mutex가 lock걸려 있는 상태에서, 다시 (동일한, 혹은 다른) signal이 들어오게 되면... mutex가 두번 lock이 걸리게 되어 deadlock이 발생할수 있다는 뜻인것 같은데... 맞나요?
저의 경우에는, signal handler에 진입할때 모든 signal을 block한 후, signal handler를 수행하고, signal처리가 끝나면 다시 signal mask를 원상복구 시키고 있습니다. 이런 방식으로 사용하는 경우에도 dead lock의 위험이 있나요?

서지훈의 이미지

signal safe를 토픽으로 찾아 보십시오.
찾아 보시면 답이 보이실 겁니다.

<어떠한 역경에도 굴하지 않는 '하양 지훈'>

#include <com.h> <beer.h> <woman.h>
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);

#include <com.h> <C2H5OH.h> <woman.h>
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);

thyoo의 이미지

FAQ를 보셔서 아시겠지만

Signal 처리 쓰레드에 관한 POSIX 표준은
1. 쓰레드 자신이 일으킨 시그널은 자신이 핸들러를 실행한다.
2. pthread_kill()에 의한 시그널은 지정된 쓰레드가 시그널을 처리한다.
3. kill()이나 tty에 의한 시그널은 프로세스의 쓰레드중에 블럭 걸리지 않은 임의의 쓰레드가 핸들러를 실행한다.

다음과 같은 경우가 발생할 수 있읍니다.

___________________________________
Less is More (Robert Browning)

댓글 첨부 파일: 
첨부파일 크기
Image icon 5.17 KB

___________________________________
Less is More (Robert Browning)

kuaaan의 이미지

예까지 들어주시고... 감사합니다. ^^;
그런데... flywoo님이 예로 들어주신것처럼
thread 1 : mutex a를 lock -> mutex b를 lock
thread 2 : mutex b를 lock -> mutex a를 lock
이런 식으로 코딩할때 데드락이 생기는 거는...
시그널 핸들러가 아니라도 마찬가지 아닌가요?
예로 들어주신 상황은 시그널 핸들러와 상관없이
절대 피해야할 코드가 아닌가 생각됩니다만...

그리고, 지순님이 말씀하신대로 검색을 해봤지만...
아직 모르겠습니다. ㅡ.ㅜ

----------------------------------------------
한번뿐인 인생....
미친듯이 살아보자!
----------------------------------------------

----------------------------------------------
한번뿐인 인생....
미친듯이 살아보자!
----------------------------------------------

thyoo의 이미지

왼쪽으로 삐져나가서 실행되는 부분이 시그널 핸들러입니다.
절대 피해야 되길래
핸들러에서 락 걸지 말라는 얘깁니다.
___________________________________
Less is More (Robert Browning)

___________________________________
Less is More (Robert Browning)

kuaaan의 이미지

이해했습니다. ^^;;
----------------------------------------------
한번뿐인 인생....
미친듯이 살아보자!
----------------------------------------------

----------------------------------------------
한번뿐인 인생....
미친듯이 살아보자!
----------------------------------------------

댓글 달기

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