쓰레드생성이 실패하는경우는 어느경우가 있을까요

jjjjrr의 이미지

안녕하세요
또질문입니다
아래코드에서여

   while(1)
    {
        client_len = sizeof(clientaddr);
        client_sockfd = accept(server_sockfd, (struct sockaddr *)&clientaddr, 
                                (socklen_t *)&client_len);

        memcpy(th_data, (void *)&client_sockfd, sizeof(client_sockfd));
        memcpy(th_data+sizeof(client_sockfd), (void *)&clientaddr, client_len); 

        // 쓰레드 생성
        if (pthread_create(&p_thread, NULL, thread_comm, (void *)th_data) == -1)
        {
            perror("thread Create error\n");
            exit(0);
        }

      }    

이부분

     if (pthread_create(&p_thread, NULL, thread_comm, (void *)th_data) == -1)
        {
            perror("thread Create error\n");
            exit(0);
        }

그러니까
쓰레드생성이 실패하는경우는 어느경우가 있을까요
제생각에는
쓰레드생성에 실패했다고 전체프로그램을 종료하는것이 옳으냐 하는겁니다
쓰레드생성이 실패하는경우들을 나누어서
프로그램종료를 해야될경우의 실패와
프로그램종료를 하지않아도 될 실패된 쓰레드생성시도만
완전히 정리할수있는방법은 없나요
동작하는 다른쓰레드는 그냥놔 두고여
우선 어느경우에 쓰레드생성이 실패하는지를 알아야 될것같은데...
조언부탁드립니다
purewell의 이미지

1. 스래드 생성 실패 요인
* 최대 스래드 개수 이상 생성하려고 했을 때
* 스래드를 위한 스택 메모리가 부족할 때
* 기타 등등 ㅡ_-);

2. 스래드 생성 실패에 따른 종료 여부
(이건 스타일? 혹은 설계 문제인 것 같은데...)
* 중요한 스래드라면 오류 메시지를 출력하고 매인 프로세스를
종료하는게 낫습니다. 그러나 아래 코드 예제를 보아하니
소켓을 이용한 서버 프로그램 같아 보이는군요.
ㅡ_-); 스래드가 생성되지 않는다고 매인 프로세스를 죽인다면
다른 연결된 클라이언트들 역시 서비스를 받지 못하겠죠.
상황에 맞는 에러처리를 해주는 것이 좋을 듯 합니다.

_____________________________
언제나 맑고픈 샘이가...
http://purewell.biz

댓글 달기

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