I am using a thread to send UDP datagrams every 4 audio blocks.
- I would implement this by starting a thread every 4 audio blocks, the thread would send the datagram and exit.
- Alternatively, I could have a while loop in the run() method of the thread always running (and sleeping) in the background, which would send the datagram whenever a given flag is set.
I would prefer the first approach, unless there is any noticeable overhead in calling startThread() and exiting the thread every time.
Is there any overhead associated with startThread() ?
Thanks Jules,
though I still need something that it is somehow clocked by the audio clock with as small a jitter as possible.
I know this is EVIL in theory, but what if instead I use DatagramSocket::waitUntilReady() with a timeout of 0 INSIDE the audio thread and, only if the socket is available I use DatagramSocket::write() to write some small message (~200bytes) to the socket? Is the time taken by write() to complete deterministic, once I check in advance that the socket was ready?