title: C++ select()/threads or an alternative to handle multiple clients in a server
body: <p>I am trying <strong>to learn C++ (with prior programming knowledge)</strong> by creating a <strong>server application with multiple clients</strong>. Server application will run on Raspberry Pi/<strong>Debian</strong> (Raspbian). I thought this would also be a good opportunity to learn about <strong>low-level concurrent programming with threads (e.g. POSIX)</strong>. Then I came across with <code>select()</code> function which basically allows usage of blocking functions in a single thread to handle multiple clients, which is interesting. Some people here on StackOverflow mentioned that <strong>threads cause a lot of overhead and <code>select()</code> seems to be a nice alternative.</strong> </p>
  
  <p>In reality, I will have 1-3 clients connected but I would like to keep my application flexible. As a structure design, I was thinking about a <strong>main thread</strong> invoking <strong>a data thread (processing stuff non-stop)</strong> and a <strong>server thread (listening for incoming connections)</strong>. Since <code>accept()</code> call is blocking, the latter one needs to be a separate thread. If a client connects, then <strong>for each client, I may need a separate thread as well</strong>.</p>
  
  <p>At the end, worker thread will write to the shared memory and <em>client threads</em> will read from there and communicate with the clients. Some people were opposing to the usage of threads but in my understanding, <strong>threads are good</strong> if they are <strong>invoked rarely</strong> (and long living) and if there are <strong>blocking function calls</strong>. For the last one as it seems there is the <code>select()</code> function, which used in a loop, allows for handling of multiple sockets in a single thread.</p>
  
  <p>I think at least for the data processing and server <code>accept()</code> call, I will need 2 separate threads initiated at the beginning. I may handle all clients with <code>select()</code> in a single thread or separate threads. What would be the correct approach and are there smarter alternatives?</p>