Exercise 1
- Thanks to the principles exposed during the lectures, transform the server code of TP 1 into a multi-threaded server, with one thread for one client.
Remarks :
- Apart from transferring the code concerning requests into the thread class, there is a problem with the Map that contains the distances of all clients.
- In a multi-threaded version of the server, this Map can be accessed by several threads concurrently. Thus, all operations on the Map are critical sections and must be protected by a mutex.
- This implies to put the Map within an object that is shared between threads, and a solution like :
- creating a new class that contains the Map (e.g. TimePool)
- to define methods in that class, which manipulate the Map accordingly to the processes that must be done when receiving a request.
- all these methods are synchronized (it may cause problem of performance but it is a reliable solution).