From cb8434c553d1bd94a9277fd65dfba38317f4acd7 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Tue, 25 Mar 2003 00:21:38 +0000 Subject: [PATCH] better sleep quantum estimator --- src/libCom/test/epicsThreadTest.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libCom/test/epicsThreadTest.cpp b/src/libCom/test/epicsThreadTest.cpp index 0bab5eaf6..3a11ee7ed 100644 --- a/src/libCom/test/epicsThreadTest.cpp +++ b/src/libCom/test/epicsThreadTest.cpp @@ -78,11 +78,12 @@ static void threadSleepQuantumTest () fflush ( stdout ); for ( unsigned i = 0u; i < iterations; i++ ) { // try to gurantee a uniform probability density function - // by intentionally burning some CPU so we are hopefully - // less likely to be aligned with the schedualing clock + // by intentionally burning some CPU until we are less + // likely to be aligned with the schedualing clock double interval = rand (); interval /= RAND_MAX; interval *= quantum; + interval += quantum / 2.0; epicsTime start = epicsTime::getCurrent (); epicsTime current = start; while ( current - start < interval ) { @@ -97,6 +98,8 @@ static void threadSleepQuantumTest () } printf ( "done\n" ); + // with a uniform probability density function the + // sleep delay error mean is one half of the quantum double quantumEstimate = 2 * errorSum / iterations; double quantumError = fabs ( quantumEstimate - quantum ) / quantum; const char * pTol = 0;