title: What is the best way to implement a cross-platform, multi-threaded server in C/C++?
body: <p>Part of the development team I work with has been given the challenge of writing a server for integration with our product. We have some low-level sensor devices that provide a C SDK, and we want to share them over a network for use by people collecting data. Sounds simple, right? Someone would connect a sensor device to their machine in one part of the building and run our server, thus sharing the device(s) with the rest of the network. Then a client would connect to that server via our application and collect sensor readings from the device.</p>
  
  <p>I created a simple, language-agnostic network protocol, and a reference implementation in Java. The problem is creating an implementation that will work with our devices that only provide an SDK written in C. We were thinking of doing the following:</p>
  
  <ol>
  <li>Create polling threads that collect and store the most recent readings from each connected device.</li>
  <li>Use a multi-threaded server to spin off each incoming connection to a worker thread.</li>
  <li>When a worker thread receives a request for a sensor reading, the most recent value collected by the polling thread is sent back to the client.</li>
  </ol>
  
  <p>That's a lot of threading, especially in C. So, to review, the general requirements are:</p>
  
  <ul>
  <li>Runs on Windows XP/Vista, Linux, and OS X machines</li>
  <li>Written in C or C++, to interact with the C SDK we have</li>
  <li>Accepts a variable number of simultaneous connections (worker threads)</li>
  <li>Must use threads, not forking (don't want to deal with another layer of IPC)</li>
  </ul>
  
  <p>Can anyone suggest a library and preferably some example code to get use started?</p>