examples/ostest: Robust mutex test needs to call pthread_mutexattr_setrobust().

This commit is contained in:
Gregory Nutt 2017-03-27 06:55:51 -06:00
parent 879d269f41
commit a3fd7fdec0
4 changed files with 34 additions and 7 deletions

View File

@ -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

View File

@ -179,7 +179,9 @@ void cancel_test(void);
/* robust.c *****************************************************************/
#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
void robust_test(void);
#endif
/* timedwait.c **************************************************************/

View File

@ -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 */

View File

@ -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);