examples/ostest: Robust mutex test needs to call pthread_mutexattr_setrobust().
This commit is contained in:
parent
879d269f41
commit
a3fd7fdec0
examples/ostest
@ -70,7 +70,11 @@ CSRCS += waitpid.c
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq ($(CONFIG_DISABLE_PTHREAD),y)
|
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)
|
ifeq ($(CONFIG_FS_NAMED_SEMAPHORES),y)
|
||||||
CSRCS += nsem.c
|
CSRCS += nsem.c
|
||||||
|
@ -179,7 +179,9 @@ void cancel_test(void);
|
|||||||
|
|
||||||
/* robust.c *****************************************************************/
|
/* robust.c *****************************************************************/
|
||||||
|
|
||||||
|
#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
|
||||||
void robust_test(void);
|
void robust_test(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* timedwait.c **************************************************************/
|
/* timedwait.c **************************************************************/
|
||||||
|
|
||||||
|
@ -388,10 +388,12 @@ static int user_main(int argc, char *argv[])
|
|||||||
cancel_test();
|
cancel_test();
|
||||||
check_test_memory_usage();
|
check_test_memory_usage();
|
||||||
|
|
||||||
|
#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
|
||||||
printf("\nuser_main: robust test\n");
|
printf("\nuser_main: robust test\n");
|
||||||
robust_test();
|
robust_test();
|
||||||
check_test_memory_usage();
|
check_test_memory_usage();
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_PTHREAD
|
#ifndef CONFIG_DISABLE_PTHREAD
|
||||||
/* Verify pthreads and semaphores */
|
/* Verify pthreads and semaphores */
|
||||||
|
@ -88,7 +88,8 @@ static FAR void *robust_waiter(FAR void *parameter)
|
|||||||
|
|
||||||
void robust_test(void)
|
void robust_test(void)
|
||||||
{
|
{
|
||||||
pthread_attr_t attr;
|
pthread_attr_t pattr;
|
||||||
|
pthread_mutexattr_t *mattr;
|
||||||
pthread_t waiter;
|
pthread_t waiter;
|
||||||
void *result;
|
void *result;
|
||||||
int nerrors = 0;
|
int nerrors = 0;
|
||||||
@ -97,7 +98,24 @@ void robust_test(void)
|
|||||||
/* Initialize the mutex */
|
/* Initialize the mutex */
|
||||||
|
|
||||||
printf("robust_test: Initializing mutex\n");
|
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)
|
if (status != 0)
|
||||||
{
|
{
|
||||||
printf("robust_test: ERROR: pthread_mutex_init failed, status=%d\n",
|
printf("robust_test: ERROR: pthread_mutex_init failed, status=%d\n",
|
||||||
@ -107,7 +125,9 @@ void robust_test(void)
|
|||||||
|
|
||||||
/* Set up pthread attributes */
|
/* Set up pthread attributes */
|
||||||
|
|
||||||
status = pthread_attr_init(&attr);
|
printf("robust_test: Starting thread\n");
|
||||||
|
|
||||||
|
status = pthread_attr_init(&pattr);
|
||||||
if (status != 0)
|
if (status != 0)
|
||||||
{
|
{
|
||||||
printf("robust_test: ERROR: pthread_attr_init failed, status=%d\n",
|
printf("robust_test: ERROR: pthread_attr_init failed, status=%d\n",
|
||||||
@ -115,7 +135,7 @@ void robust_test(void)
|
|||||||
nerrors++;
|
nerrors++;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pthread_attr_setstacksize(&attr, STACKSIZE);
|
status = pthread_attr_setstacksize(&pattr, STACKSIZE);
|
||||||
if (status != 0)
|
if (status != 0)
|
||||||
{
|
{
|
||||||
printf("robust_test: ERROR: pthread_attr_setstacksize failed, status=%d\n",
|
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.
|
* seconds, and exit holding the mutex.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
printf("robust_test: Starting thread\n");
|
status = pthread_create(&waiter, &pattr, robust_waiter, NULL);
|
||||||
status = pthread_create(&waiter, &attr, robust_waiter, NULL);
|
|
||||||
if (status != 0)
|
if (status != 0)
|
||||||
{
|
{
|
||||||
printf("robust_test: ERROR: pthread_create failed, status=%d\n", status);
|
printf("robust_test: ERROR: pthread_create failed, status=%d\n", status);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user