poll함수에 대한 질문 입니다.

hyper9의 이미지

일전에 질문드린 Code와 비슷한 code인데, 이번에는 poll()함수에 대해
여쭤보고 싶어서요 ..

아래와 같은 code가 있는데, test_thread-1을 인쇄하고, test_thread-2는 인쇄하지
않은 상태에서 program이 정지한 것 처럼 보이는데요.

그 이유가 뭘까를 찾다가 질문을 드립니다.

물론 이 code가 전체는 아니고요.
일부분이고, 질문을 위해서 poll함수부분만을 발췌한 것인데요.
poll()이 event를 기다리다가, event가 발생하지 않으니까 무한정
기다리는 상황이 아닌가 추측을 하는데, 이게 맞는 생각일까요?

그리고 이런 경우에 정상으로 test_thread-2를 print하려면 어떤 일이 발생이되어야
하는 걸까요?
어떤 전형적인 모습들이 있을까요?

그럼 그걸 hint로 좀더 찾아보려고 하는데요 ,,,
아직은 어떤 hint가 없어서, 계속 여기저기 쳐다만 보면서 진도가 안나가는 상황이라
질문을 올려봅니다.

어떤식으로 접근을 하는 것이 현명한지 여쭤보고 싶어서요.
그럼,,,조언 부탁드립니다..미리 감사드려요 ~

#include <stdio.h>
#include <pthread.h>
 
static void *test_thread(void *ctx);
static pthread_t test_pthread;
 
int main(void)
{
 
   int   err;   
 
   err = pthread_create(&test_pthread, NULL, test_thread, NULL);
 
   if (err)
      printf("unable start test_thread \n");
 
   pthread_join(test_pthread, NULL);
   return 0;     
}
 
void *test_thread(void *ctx)
{
   struct pollfd test;
   int	error;
 
   test.fd = test_sock;
   test.events = POLLIN | POLLPRI;
 
   while(1)
   {
      printf("test_thread-1 \n");
      error = poll(test&, 1, -1);
      printf("test_thread-2 \n");
   }
 
   return NULL;
}
jos77의 이미지

poll 함수가 뭔지 모르고 하시는 질문이신가요? select 나 poll 은 file / socket descriptor 를 demultiplex 처럼 처리하는 함수인데 마치 sleep() 이나 wait() 처럼 질문하시네요.
test_sock 이 가리키는 fd 에 write 하면 동작할 겁니다. 아니면 poll 의 세번째 파라미터 timeout 을 -1 값에서 적당한 milleseconds 값으로 바꾸세요.

-----
안녕하세요 소프트웨어 공학센터 장원석 책임입니다.
http://www.software.kr

댓글 달기

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