8

I have written a TCP server with Win32 API and C++ but it's single-threaded. Can anyone tell me how would I go about making it multi-threaded? I imagine for every new accepted connection, I'd have to spawn a thread that takes care of it. But I have never had experience with threading in Win32. Can anyone tell me how I would go about threaded programming with Win32 and C++?

bodacydo
  • 75,521
  • 93
  • 229
  • 319
  • 3
    Call `CreateThread()`. This question is too general. – David Heffernan Aug 31 '11 at 16:32
  • Note that one-thread-per-socket setups are almost never the right design. I suggest you look into a setup with a fixed number of threads either using non-blocking sockets or [I/O completion ports](http://msdn.microsoft.com/en-us/library/aa365198(v=vs.85).aspx). – André Caron Aug 31 '11 at 16:38
  • Note: eventually, you can use boost::thread library. – neodelphi Aug 31 '11 at 16:44

1 Answers1

5

Read the documentation of :

And you can also see an example in my answer here:

Community
  • 1
  • 1
Nawaz
  • 353,942
  • 115
  • 666
  • 851