I have an implemented UDP receiver which is continuously receiving DTN packets (UDP encapsulated) and performing some operations on them. This whole process is working on a single main thread. However this consumes time on processing the packets and results in packet lost when a sender sends a huge chunk of data.
int main(int argc, char *argv[])
{
while(1)
{
std::vector<char> data(64535);
size_t len = sock->recvfrom(&data[0], maxlen, 0, fromAddress);
// perform operation on the packets received (a bit of time consuming)
..................
..................
}
}
I would like to use Multhithreading to overcome packets loss by moving the packet processing code to a different thread. My motive is to continuously receive packets on one thread (Thread 1) which is always running in a while loop and storing packets in a Queue (FIFO) in order to avoid loss of packets.
The other thread (Thread 2) will be doing operation on the packets received. Thread 2 should be called via event call from Thread 1 as soon as a packet is stored in a Queue.
Is the scenario even realistic? I am new with multithreading so just want to get some startup information to proceed in C++. Also if my format of asking the question is not according to standard, please let me know :)