{질문}쓰레드 서버 프로그래밍..중에..

익명 사용자의 이미지

쓰레드로 서버 프로그래밍을 하는데...
서버 접속..-> 쓰레드 생성 -> 쓰레드가 할일하다가 --> 쓰레드 종료
이리 했는데....
3500번 정도 쓰레드를 생성햇는데.. 물론.. 일 끝나면 쓰레드 종료 해줬구
여... 근데.. 3500개 정도 밖에 생성을 못하더군여..
쓰레드가 게속 쌓이던데... 왜 종료를 해도 초기화가 안되는것인지...
쓰레드 풀을 쓰면 된다는데... 예제나... 자세한 설명은 어딨는지..
궁금합니다. 많이 찾아봤구여 -_- 근데 자료가 많이 없더군여..
씨로 개발중이며.. 리눅스에서 프로그래밍 중입니다 pthread이구엽.
좋은 답변 부탁 드립니다.

익명 사용자의 이미지


훔.... 제가 보기에는 thread를 join해 주시지 않거나
thread생성시에 detach 상태로 안 해 주신 듯 합니다.
detach 상태로 생성되지 않은 thread가 자체적으로
pthread_detach(pthread_self()) 등으로 detach를 시키지 않으면
thread 종료시에 thread에 관한 정보를 보관하고 있습니다.
이후 다른 thread가 pthread_join() 함수를 이용해서 이 정보를
가져가게 되고요.
fork()로 생성된 애가 wait() 등으로 정보 가져가는 것과 비슷하져..

제가 테스트 해 본 장비에서는 255개까지 thread 종료하면
그 후부터는 pthread_create()에서 오류를 내더군요.
굳이 종료가 아니라 계속 수행하게 해도 255에서 더 이상
thread를 생성하지 못하네요.
11 Resource temporarily unavailable

thread를 detach상태로 바꾸니까 계속 생성해도 문제없이 생성되네요.

thread pool 은 thread 관련 책에 보시면 다들 예제로 들어놨을 것
같은데요.
Programming with POSIX Threads 라는 책도
말이 좀 많아서 그렇지, thread pool에 관한 예제가 있습니다.
다른 곳에서도 여럿 찾으실 수 있을 것이고요.

흠.. 근데 전 맨 처음에 리눅스에서 쓰레드가
프로세스를 이용해서 구현된 것 보고 정말 깼습니다.
(뭐 나름대로 속사정이 있겠죠..)
분명 멀티 쓰레드로 짰는데, ps 해 보니 프로세스가
여러개 나오지 않겠어요? ㅡ.ㅡ;;

댓글 달기

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