Click here to Skip to main content
15,887,485 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questioncalling OnDraw() Pin
susanne13-Jul-09 4:09
susanne13-Jul-09 4:09 
AnswerRe: calling OnDraw() Pin
Stuart Dootson3-Jul-09 5:34
professionalStuart Dootson3-Jul-09 5:34 
GeneralRe: calling OnDraw() Pin
susanne14-Jul-09 7:05
susanne14-Jul-09 7:05 
GeneralRe: calling OnDraw() Pin
Stuart Dootson4-Jul-09 7:33
professionalStuart Dootson4-Jul-09 7:33 
Questionwhat is the entry id for junk mail Pin
santhosh-padamatinti3-Jul-09 3:54
santhosh-padamatinti3-Jul-09 3:54 
Questionxmlhttp improper response Pin
Ash_VCPP3-Jul-09 2:28
Ash_VCPP3-Jul-09 2:28 
AnswerRe: xmlhttp improper response Pin
Stuart Dootson3-Jul-09 3:34
professionalStuart Dootson3-Jul-09 3:34 
Questionthreads and their time slots. [modified] Pin
Souldrift2-Jul-09 23:45
Souldrift2-Jul-09 23:45 
Good morning Smile | :) ,

just a brief question.
I got a multi-threaded program. Now is it possible to ensure that a certain thread at a certain point won´t lose its 'working permission'.
Hm, don´t know if I expressed that correctly.
I have a thread going into a function where it has to wait for a previously defined time, then go on. The thing is, it waits and waits and at some point its time slot is taken away. When it is given the next slot, though, the time it has waited for has 'long' passed. And thus it´s always too late.

The code in question is:

int RTPEngine::SendRTPPacket( BYTE* data, int size )
{
	if( data && size > 0 && m_pHeader )
	{
		m_pLogger->Out(Logger::DEBUG, "RTPEngine: Sending data package with size %d (excluding header).\n", size);

		BYTE* packet = new BYTE[size+12];
		BYTE* headerBytes = m_pHeader->GetInc();

		for( int i = 0; i < 12; i++ )
		{
			packet[i] = headerBytes[i];
		}
		for( int i = 0; i < size; i++ )
		{
			packet[i+12] = data[i];
		}

		double now = 0.0; // milliseconds
		if( m_dPacketSendTime != 0.0 )
		{
			now = ((double) clock() / CLK_TCK) * 1000; // milliseconds
			int tmp = 0;
			//m_pLogger->Out( Logger::DEBUG, "RTPEngine: Time now = %f.\n", now );
			while( now <= m_dPacketSendTime )
			{
				if( tmp >= 20 )
				{
					m_pLogger->Out( Logger::DEBUG, "RTPEngine: Time now = %f, send time = %f.\n", now, m_dPacketSendTime );
					tmp = 0;
				}
				tmp++;
				now = ((double) clock() / CLK_TCK) * 1000;
			}
		}

		now = ((double) clock() / CLK_TCK) * 1000;
		int rc=sendto(m_oUDPSocket,(char*)packet,size+12,0,(SOCKADDR*)&m_oUDPAddress,sizeof(SOCKADDR_IN));

		m_pLogger->Out( Logger::DEBUG, "RTPEngine: Packet sent at = %f.\n", now );

		m_dPacketSendTime = ((double) clock() / CLK_TCK) * 1000; // milliseconds
		m_dPacketSendTime += (m_dPacketLengthMillis*(1.0 - m_dRTPOverlap));
		m_pLogger->Out( Logger::DEBUG, "RTPEngine: Next send time = %f.\n", m_dPacketSendTime );

		return size;
	}
	else
		return 0;
}


And one more thing is, on my Vista machine it works fine. The logger prints this:

RTPEngine: Next send time = 53637.795918.
RTPEngine: Sending data package with size 480 (excluding header).
RTPEngine: Time now = 53628.000000, send time = 53637.795918.
.
.
.
RTPEngine: Time now = 53636.000000, send time = 53637.795918.
RTPEngine: Time now = 53636.000000, send time = 53637.795918.
RTPEngine: Time now = 53637.000000, send time = 53637.795918.
RTPEngine: Time now = 53637.000000, send time = 53637.795918.
RTPEngine: Time now = 53637.000000, send time = 53637.795918.
RTPEngine: Packet sent at = 53638.000000.

On our server (XP) where it has to actually run later, it gives me this:

RTPEngine: Next send time = 53637.795918.
RTPEngine: Sending data package with size 480 (excluding header).
RTPEngine: Time now = 53628.000000, send time = 53637.795918.
.
.
.
RTPEngine: Time now = 53628.000000, send time = 53637.795918.
RTPEngine: Time now = 53628.000000, send time = 53637.795918.
RTPEngine: Time now = 53628.000000, send time = 53637.795918.
RTPEngine: Time now = 53628.000000, send time = 53637.795918.
RTPEngine: Time now = 53628.000000, send time = 53637.795918.
RTPEngine: Time now = 53628.000000, send time = 53637.795918.
RTPEngine: Packet sent at = 53644.000000.

As you can see ... too late Smile | :) .

Any ideas?

Souldrift

modified on Friday, July 3, 2009 6:20 AM

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 
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 

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.