Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

[SOLVED] An issue with 'tbb::tick_count' class

SergeyKostrov
Valued Contributor II
432 Views

I detected an issue with 'tbb::tick_count' class. Please take a look at a test-case:

...
tbb::tick_count starttick;
tbb::tick_count endtick;

starttick = tbb::tick_count::now();
::Sleep( 5000 ); // 5000 ms = 5 seconds
endtick = tbb::tick_count::now();
_tprintf( _T("Task Delay: %ld secs\\n"), ( int )( endtick - starttick ).seconds() );
...

A delay is 5 seconds. However, '( endtick - starttick ).seconds()' returns 4 seconds. It is reproducible
with a test application compiled in Debug and Release configurations and TBBs v4 updates 3 and 1.

A generic description of the problem is as follows:

If a delay of N seconds is expected then '( endtick - starttick ).seconds()' always returns N-1 seconds.

My Development Environment:

OS : Windows XP 32-bit SP3
IDE: Visual Studio 2005 SP1
TBB: Version 4 Update 3
TBB: Version 4 Update 1

0 Kudos
5 Replies
RafSchietekat
Valued Contributor III
432 Views
What do you get without casting to an integral type (which discards the entire fractional part)? And how would you be able to tell that it isn't Sleep() that's returnng a fraction too early? Have you compared with other timng API, or inspected the source code?
0 Kudos
Vladimir_P_1234567890
432 Views
hello, what is a result in ms? ::Sleep() can return eariler than its arg. If result is 4999ms expect that result in seconds is '4'.

--Vladimir
0 Kudos
SergeyKostrov
Valued Contributor II
432 Views
hello, what is a result in ms? ::Sleep() can return eariler than its arg. If result is 4999ms expect that result in seconds is '4'.

--Vladimir


I would expect an opposite due to amultitaskingin Windows OS.So,a real interval could be more than 5000ms.

0 Kudos
SergeyKostrov
Valued Contributor II
432 Views
What do you get without casting to an integral type (which discards the entire fractional part)? And how would you be able to tell that it isn't Sleep() that's returnng a fraction too early? Have you compared with other timng API, or inspected the source code?


Thanks for these tips andI'll take a look tomorrow.
Best regards,
Sergey

0 Kudos
SergeyKostrov
Valued Contributor II
432 Views

[SOLVED]. A 'seconds()' method returns aresult as a double-precisionfloating-pointvalue ( type 'double' ).

A modified test-case:

...
tbb::tick_count starttick;
tbb::tick_count endtick;

starttick = tbb::tick_count::now();
::Sleep( 2000 );
endtick = tbb::tick_count::now();
_tpintf( _T("Task Delay: %f secs\n"), ( endtick - starttick ).seconds() );
_tpintf( _T("Task Delay: %1.f secs\n"), ( endtick - starttick ).seconds() );
...

outputs correct results:

...
Task Delay: 1.988046 secs
Task Delay: 2 secs // Rounded by '_tprintf' to 1 digit
...

0 Kudos
Reply