Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
2403 Discussions

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

SergeyKostrov
Valued Contributor II
96 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
Black Belt
96 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?
Vladimir_P_Intel2
96 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
SergeyKostrov
Valued Contributor II
96 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.

SergeyKostrov
Valued Contributor II
96 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

SergeyKostrov
Valued Contributor II
96 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
...

Reply