네트워킹프로그래밍에서 쓰레드 처리 어떻게 하나요

nerkis의 이미지

ftp 서버를 하고 있는데
소켓 만들고 바인드하고 액셉트 하고 나서 쓰레드를 만들어서 함수를 실행하게 했는데

이렇게 되니 자원을 공유하더라구요. 이렇게 되니 a에서 ddd라는 디렉토리로 이동했는데
eee라는 엉뚱한 폴더로 가게되고..

독립적으로 쓰레드를 구현하는 것도 되나요
만약 그렇게 된다면 같은 포트를 쓰게 되는데 그런 문제는 어떻게 되는건지 너무 궁금합니다.

JuEUS-U의 이미지

POSIX 쓰레드의 개념입니다.

Quote:
# Threads in the same process share:
* Process instructions
* Most data
* open files (descriptors)
* signals and signal handlers
* current working directory
* User and group id

# Each thread has a unique:
* Thread ID
* set of registers, stack pointer
* stack for local variables, return addresses
* signal mask
* priority
* Return value: errn

그러니까 쓰레드는 프로세스 내에서 다른 작업을 동시에 수행하기위한 존재가 되겠죠.
필연적으로 자원을 공유할 수 밖에 없습니다.
새로 프로세스를 만드는게 정답이겠네요.-ㅅ-;

소켓 문제는 프로세스간 통신으로 해결될 것 같네요.

codepage의 이미지

개념적으로 본다면 쓰래드는 '작은 프로세스'라는 개념입니다.
또한 프로세스 간의 데이타를 교환할 경우 shared memory나
IPC(Interprocess CAll) 같은 개념을 썼는데
쓰래드는 한 프로세스의 매모리를 공유하므로 이러한 난해한 작업도 줄어든다는 잇점이 있고.
프로세스를 fork하는 것보다 훨씬 cost가 적게 든다는 장점이 있습니다.

결론적으로 말하면 multi-threaded ftp server는 구현 가능합니다.
님의 문제는 별개의 쓰래드 간에 간섭이 일어났다고 보는데요
설계상에 분병히 오류가 있다고 보여지고요
각 쓰래드별로 논리적으로 별개의 메모리를 가지고 핸들링 했는지 검토해 보시기 바랍니다.
ftp 포트를 리스닝 하고 있다가 들어온 소켓 디스크립터를
각각 독립적인 worker thread에다가 할당해 주어야 하고요
작업이 끝났을 경우 놀고 있는 쓰래드를 어떻게 관리할 지도 생각해봐야 겠지요.
어차피 시스템 사양에 따라 동시에 돌릴 수 있는 쓰래드의 수는 제한되어 있으니까요.
이 숫자 같은것을 configuration file에 넣고 그 설정에 따라 서버가 기동되게 하는 것도 필요합니다.

댓글 달기

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