iocp간 독립적?

Lightstar의 이미지

하나의 서버가 2개의 클라이언트와 데이터 통신을 하도록 하려고 컴플리션포트를 2개 만들었습니다.

2개의 클라이언트가 서버와 통신하는 작업내용은 서로 다릅니다.

hComPort=CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0);

hComPortl=CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0);

hThread=CreateThread(NULL, 0, WorkerThread, hComPort, 0, &ThreadId);

hThreadl=CreateThread(NULL, 0, WorkerThreadl, hComPortl, 0, &ThreadIdl);

각각의 워크스레드 함수도

DWORD WINAPI WorkerThread(LPVOID arg){...} 이걸 a번

DWORD WINAPI WorkerThreadl(LPVOID arg){...} 이걸 b번

이렇게 다 만들어주었습니다.

그런데 a번에서 클라이언트와의 처리가 막 되고 있는 도중, b에서 while(1){}에 들어갑니다.

이러면 원래 a번 작업도 멈추는게 정상인가요?

디버깅을 하면서 b에서 while문을 빠져나오면 다시 a의 통신처리가 이어서 제대로 되는걸 확인했습니다.

제가 이해가 부족한건지 쓰레드를 따로 돌렸는데 한쪽이 무한루프에 빠진다고 다른쪽이 안되는게 이상합니다.

mirheekl의 이미지

NumberOfConcurrentThreads [in]
The maximum number of threads that the operating system can allow to concurrently process I/O completion packets for the I/O completion port. This parameter is ignored if the ExistingCompletionPort parameter is not NULL.
If this parameter is zero, the system allows as many concurrently running threads as there are processors in the system.

이걸 0으로 주셨으니 시스템이 알아서 할당하는 값이 들어갔을 것인데, 그 기본값이 바로 코어의 수라고 합니다. 따라서 싱글코어 시스템이라면 한 번에 한 개의 워커 스레드만 동작을 하겠지요.

싱글코어 환경이 아니라면 다른 문제가 있는 것이고, 싱글코어가 맞다면 저 숫자를 바꿔주시면 도움이 될겁니다. 다만, 그렇다 해도 워커 스레드 하나가 무한루프에 가까운 상태가 되는 것을 그대로 두는 것은 좋지 않을듯 합니다. IOCP를 쓰지 않고 일반적인 멀티스레딩을 하더라도 저런 경우에는 서로 퍼포먼스 영향을 받게 됩니다.

--

Lightstar의 이미지

hThreadl=CreateThread(NULL, 0, WorkerThreadl, hComPortl, 0, &ThreadIdl);
이 작업을 for문에서 여러번 반복하여 만들고 있습니다. 지금 소스를 보진 못하는데 그렇게 알고 있습니다.
각각 프로세서의 2배-2개의 숫자만큼 스레드를 만들라구요.
싱글코어환경은 아니구요...
하나의 워크쓰레드에서 서로 while문에 빠질 때는 서로 간섭을 주지 않습니다.
b번 작업이 2개 돌고 있을 때 하나가 while에 빠져도 다른 하나는 잘 작업 합니다.
그런데 b번 하나가 while(1)에 빠지면 a번 작업이 일시중지 됩니다;;

댓글 달기

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