4 ms·
One time, I wrote a small network protocol stack to handle some proprietary UDP-based protocol that supported fragmentation. Since the header on each fragment
by Unklejoe 6y ago
One time, I wrote a small network protocol stack to handle some proprietary UDP-based protocol that supported fragmentation.
Since the header on each fragment contained the total message size, I was able to pre-allocate the full size of the message upon receipt of the first fragment.
Then, as fragments arrived, I would copy their data into their respective areas of the message.
Typically, everything would arrive in order, so the message would be copied from beginning to end, piece by piece.
However, since this was Ethernet/UDP, it was possible for frames to arrive out of order.
This would result in the message being pieced together, with each fragment filling in its hole until all fragments have been received.
I guess this is a form of a data race? Or rather, a case where a data race at least wasn't detrimental.
- Liquid_Fire 6y agoA data race requires multiple threads to access the same memory at the same time and at least one of them to be writing the data. There is no data race in your example, since the fragments are all written to different parts of memory, unless you had something else reading the message while the individual fragments were still being written.
- deleted 6y ago[deleted]