I am designing a client and server socket program.
I have a file to be transferred to the server from the client using UDP, I repeat I am using UDP…..
I am sending through UDP so, the sending rate is too fast then the receiver, so I have created 3 threads listening on the same socket, so that when one thread is doing some work(I mean writing to a file using fwrite) with the received data the other thread can recv from the client.
My 1st question is when I am using a fwrite with multiple threads I have to use locks as the file pointer is shared between the threads. I am right in thinking???
My 2nd question is “Will there be any improvement in the performance if I use multiple threads to fwrite using locks over using a single thread to do the fwrite work with no locks…??? ” … Please guide me…
Similar to Ed’s answer, I’d suggest using asynchronous I/O and a single thread for your server. Though I find using Boost.Asio easier than posix AIO.