diff --git a/examples/ostest/Makefile b/examples/ostest/Makefile index 7517cd87f..ca8d145e7 100644 --- a/examples/ostest/Makefile +++ b/examples/ostest/Makefile @@ -70,7 +70,11 @@ CSRCS += waitpid.c endif ifneq ($(CONFIG_DISABLE_PTHREAD),y) -CSRCS += cancel.c robust.c cond.c mutex.c sem.c semtimed.c barrier.c timedwait.c +CSRCS += cancel.c cond.c mutex.c sem.c semtimed.c barrier.c timedwait.c + +ifneq ($(CONFIG_PTHREAD_MUTEX_UNSAFE),y) +CSRCS += robust.c +endif ifeq ($(CONFIG_FS_NAMED_SEMAPHORES),y) CSRCS += nsem.c diff --git a/examples/ostest/ostest.h b/examples/ostest/ostest.h index 351567494..17ee5b85d 100644 --- a/examples/ostest/ostest.h +++ b/examples/ostest/ostest.h @@ -179,7 +179,9 @@ void cancel_test(void); /* robust.c *****************************************************************/ +#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE void robust_test(void); +#endif /* timedwait.c **************************************************************/ diff --git a/examples/ostest/ostest_main.c b/examples/ostest/ostest_main.c index 595599ec5..d303a9be4 100644 --- a/examples/ostest/ostest_main.c +++ b/examples/ostest/ostest_main.c @@ -388,10 +388,12 @@ static int user_main(int argc, char *argv[]) cancel_test(); check_test_memory_usage(); +#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE printf("\nuser_main: robust test\n"); robust_test(); check_test_memory_usage(); #endif +#endif #ifndef CONFIG_DISABLE_PTHREAD /* Verify pthreads and semaphores */ diff --git a/examples/ostest/robust.c b/examples/ostest/robust.c index 2d8383659..40eefc4c3 100644 --- a/examples/ostest/robust.c +++ b/examples/ostest/robust.c @@ -88,7 +88,8 @@ static FAR void *robust_waiter(FAR void *parameter) void robust_test(void) { - pthread_attr_t attr; + pthread_attr_t pattr; + pthread_mutexattr_t mattr; pthread_t waiter; void *result; int nerrors = 0; @@ -97,7 +98,24 @@ void robust_test(void) /* Initialize the mutex */ printf("robust_test: Initializing mutex\n"); - status = pthread_mutex_init(&g_robust_mutex, NULL); + + status = pthread_mutexattr_init(&mattr); + if (status != 0) + { + printf("robust_test: ERROR: pthread_mutexattr_init failed, status=%d\n", + status); + nerrors++; + } + + status = pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST); + if (status != 0) + { + printf("robust_test: ERROR: pthread_mutexattr_setrobust failed, status=%d\n", + status); + nerrors++; + } + + status = pthread_mutex_init(&g_robust_mutex, &mattr); if (status != 0) { printf("robust_test: ERROR: pthread_mutex_init failed, status=%d\n", @@ -107,7 +125,9 @@ void robust_test(void) /* Set up pthread attributes */ - status = pthread_attr_init(&attr); + printf("robust_test: Starting thread\n"); + + status = pthread_attr_init(&pattr); if (status != 0) { printf("robust_test: ERROR: pthread_attr_init failed, status=%d\n", @@ -115,7 +135,7 @@ void robust_test(void) nerrors++; } - status = pthread_attr_setstacksize(&attr, STACKSIZE); + status = pthread_attr_setstacksize(&pattr, STACKSIZE); if (status != 0) { printf("robust_test: ERROR: pthread_attr_setstacksize failed, status=%d\n", @@ -127,8 +147,7 @@ void robust_test(void) * seconds, and exit holding the mutex. */ - printf("robust_test: Starting thread\n"); - status = pthread_create(&waiter, &attr, robust_waiter, NULL); + status = pthread_create(&waiter, &pattr, robust_waiter, NULL); if (status != 0) { printf("robust_test: ERROR: pthread_create failed, status=%d\n", status);