Note that there are some explanatory texts on larger screens.

plurals
  1. POWinsock uncontrollably spawns several, persistent threads
    primarykey
    data
    text
    <p>I'm designing a networking framework which uses <code>WSAEventSelect</code> for asynchronous operations. I spawn one thread for every 64th socket due to the max 64 events per thread limitation, and everything works as expected except for one thing:</p> <p>Threads keep getting spawned uncontrollably by Winsock during connect and disconnect, threads that won't go away.</p> <p>With the current design of the framework, two threads should be running when only a few sockets are active. And as expected, two threads are running in total. However, when I connect with a few sockets (1-5 sockets), an additional 3 threads are spawn which persist until I close the application. Also, when I lose connection on any of the sockets, 2 more threads are spawned (also persisting until closure). That's 7 threads in total, 5 of which I have no idea what they are there for.</p> <p>If they are required by Winsock for connecting or whatever and then disappeared, that would be fine. But it bothers me that they persist until I close my application.</p> <p>Is there anyone who could shed some light on this? Possibly a solution to avoid these threads or force them to close when no connections are active?</p> <p>(Application is written in C++ with Win32 and Winsock 2.2)</p> <hr> <p><strong>Information from Process Explorer:</strong> </p> <p><strong>Expected threads:</strong><br> MyApp.exe!WinMainCRTStartup<br> MyApp.exe!Netfw::NetworkThread::ThreadProc </p> <p><strong>Unexpected threads:</strong><br> ntdll.dll!RtlpUnWaitCriticalSection+0x2dc<br> mswsock.dll+0x7426<br> ntdll.dll!RtlGetCurrentPeb+0x155<br> ntdll.dll!RtlGetCurrentPeb+0x155<br> ntdll.dll!RtlGetCurrentPeb+0x155 </p> <p>All of the unexpected threads have call stacks with calls to functions such as <code>ntkrnlpa.exe!IoSetCompletionRoutineEx+0x46e</code> which probably means it is a part of the notification mechanism.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload