Click here to Skip to main content
15,888,461 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionthreads and their time slots. [modified] Pin
Souldrift2-Jul-09 23:45
Souldrift2-Jul-09 23:45 
AnswerRe: threads and their time slots. Pin
Stuart Dootson3-Jul-09 0:31
professionalStuart Dootson3-Jul-09 0:31 
GeneralRe: threads and their time slots. [modified] Pin
Souldrift3-Jul-09 1:17
Souldrift3-Jul-09 1:17 
GeneralRe: threads and their time slots. Pin
Stuart Dootson3-Jul-09 1:58
professionalStuart Dootson3-Jul-09 1:58 
GeneralRe: threads and their time slots. Pin
Souldrift3-Jul-09 2:43
Souldrift3-Jul-09 2:43 
GeneralRe: threads and their time slots. Pin
Stuart Dootson3-Jul-09 3:30
professionalStuart Dootson3-Jul-09 3:30 
GeneralRe: threads and their time slots. Pin
Souldrift3-Jul-09 5:44
Souldrift3-Jul-09 5:44 
AnswerRe: threads and their time slots. Pin
Roger Stoltz3-Jul-09 2:09
Roger Stoltz3-Jul-09 2:09 
As Stuart already stated - windows is not a real-time operating system.
You might find this article[^] on the subject interesting.

However, I'm curious about why you need to send data with such accuracy you seem to be aiming for. Since you're using UDP sockets there's always going to be some kind of network latency that you cannot do anything about and it may not be the same for each packet sent.

It seems to me as if this is about RTP, i.e. Real-time Transport Protocol, since the name of your class is RTPEngine.
If this is the case then you shouldn't have to worry about timing when sending the data. Every RTP-packet has a timestamp that the receiver should use in order to figure out when the media data in the packet should be played.
Read more about RTP here[^].

If you cannot make use of the timestamp in the RTP-packets, or if this is really not about RTP, I'd try the following:
  1. Create a sending worker thread that reads data packets from a queue, e.g. std::queue; the packets are added to the queue by another thread, probably the main thread.
  2. The sending thread waits on a semaphore, with e.g. ::WaitForMultipleObjects(), that is released once for each packet added to the queue. The trick here is that a thread waiting on a synchronization object, such as a semaphore, gets a temporary priority boost when the object is signalled which means that it will be scheduled to run ASAP.
  3. Each data packet has a waitable timer created and set by the thread that adds the packets to the queue. The sending thread then waits on the timer and sends the data when that the timer is signalled.

I would create a class that represents a packet with a waitable timer as a member. I would also use reference counting smart pointers that reflects the data packets as elements of the queue; this way I don't have to worry about writing cleaning up code in my sending thread. When the object goes out of scope everything is released - heap and waitable timers.

For more information on worker threads - read this[^].
For more information on reference counting smart pointer - read this[^] and some examples here[^].


"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown


GeneralRe: threads and their time slots. Pin
Souldrift3-Jul-09 2:50
Souldrift3-Jul-09 2:50 
AnswerRe: threads and their time slots. Pin
Keith Worden3-Jul-09 5:29
Keith Worden3-Jul-09 5:29 
GeneralRe: threads and their time slots. Pin
Souldrift3-Jul-09 6:04
Souldrift3-Jul-09 6:04 
AnswerRe: threads and their time slots. Pin
Souldrift3-Jul-09 6:07
Souldrift3-Jul-09 6:07 
GeneralRe: threads and their time slots. Pin
Keith Worden3-Jul-09 6:18
Keith Worden3-Jul-09 6:18 
GeneralRe: threads and their time slots. Pin
Souldrift3-Jul-09 6:39
Souldrift3-Jul-09 6:39 
AnswerRe: threads and their time slots. Pin
Souldrift3-Jul-09 6:48
Souldrift3-Jul-09 6:48 
AnswerRe: threads and their time slots. Pin
Souldrift3-Jul-09 7:34
Souldrift3-Jul-09 7:34 
GeneralRe: threads and their time slots. Pin
Stuart Dootson3-Jul-09 8:33
professionalStuart Dootson3-Jul-09 8:33 
GeneralRe: threads and their time slots. Pin
Roger Stoltz3-Jul-09 8:41
Roger Stoltz3-Jul-09 8:41 
GeneralRe: threads and their time slots. Pin
Stuart Dootson3-Jul-09 8:50
professionalStuart Dootson3-Jul-09 8:50 
GeneralRe: threads and their time slots. Pin
Roger Stoltz3-Jul-09 8:55
Roger Stoltz3-Jul-09 8:55 
GeneralRe: threads and their time slots. Pin
Souldrift5-Jul-09 21:37
Souldrift5-Jul-09 21:37 
GeneralRe: threads and their time slots. Pin
Stuart Dootson5-Jul-09 21:43
professionalStuart Dootson5-Jul-09 21:43 
GeneralRe: threads and their time slots. [modified] Pin
Souldrift5-Jul-09 22:19
Souldrift5-Jul-09 22:19 
GeneralRe: threads and their time slots. Pin
Stuart Dootson5-Jul-09 23:30
professionalStuart Dootson5-Jul-09 23:30 
AnswerRe: threads and their time slots. Pin
Roger Stoltz3-Jul-09 8:39
Roger Stoltz3-Jul-09 8:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.