To make sure that threads are blocked on mutex, bind all to single CPU. Because they all use SCHED_FIFO policy with main thread having the lowest priority, main will progress only after three created threads block on mutex.
Signed-off-by: Jan Stancek <[email protected]> --- .../interfaces/pthread_attr_setschedpolicy/2-1.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setschedpolicy/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setschedpolicy/2-1.c index 80ce906..af8e3e4 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setschedpolicy/2-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setschedpolicy/2-1.c @@ -20,6 +20,7 @@ * Date: 20/05/2011 */ +#define _GNU_SOURCE #include <stdio.h> #include <string.h> #include <pthread.h> @@ -27,11 +28,13 @@ #include <stdlib.h> #include <errno.h> #include <posixtest.h> +#include <affinity.h> /* Priorities for the threads, must be unique, non-zero, and ordered */ #define PRIO_HIGH 20 #define PRIO_MED 10 #define PRIO_LOW 5 +#define PRIO_MAIN 1 static int priorities[3]; @@ -142,9 +145,20 @@ int main(void) pthread_t t1; pthread_t t2; pthread_t t3; + struct sched_param sp; status = PTS_UNRESOLVED; + + rc = set_affinity(0); + if (rc) + FAIL_AND_EXIT("set_affinity", errno); + + sp.sched_priority = PRIO_MAIN; + rc = pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp); + if (rc) + FAIL_AND_EXIT("pthread_setschedparam()", rc); + rc = pthread_mutex_lock(&mutex); if (rc) FAIL_AND_EXIT("pthread_mutex_lock()", rc); -- 1.7.1 ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
