Add small test of pthread_exit()/pthread_self() on main thread.
This commit is contained in:
parent
7bfd623616
commit
6d9259f334
@ -66,6 +66,10 @@ CSRCS += cancel.c cond.c mutex.c timedmutex.c sem.c semtimed.c barrier.c
|
|||||||
CSRCS += timedwait.c
|
CSRCS += timedwait.c
|
||||||
CSRCS += pthread_rwlock.c pthread_rwlock_cancel.c
|
CSRCS += pthread_rwlock.c pthread_rwlock_cancel.c
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_SCHED_WAITPID),y)
|
||||||
|
CSRCS += pthread_exit.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifneq ($(CONFIG_TLS_NELEM),0)
|
ifneq ($(CONFIG_TLS_NELEM),0)
|
||||||
CSRCS += specific.c
|
CSRCS += specific.c
|
||||||
endif
|
endif
|
||||||
|
@ -230,6 +230,12 @@ void pthread_rwlock_test(void);
|
|||||||
|
|
||||||
void pthread_rwlock_cancel_test(void);
|
void pthread_rwlock_cancel_test(void);
|
||||||
|
|
||||||
|
/* pthread_exit.c ***********************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_SCHED_WAITPID
|
||||||
|
void pthread_exit_test(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* pthread_cleanup.c ********************************************************/
|
/* pthread_cleanup.c ********************************************************/
|
||||||
|
|
||||||
void pthread_cleanup_test(void);
|
void pthread_cleanup_test(void);
|
||||||
|
@ -441,6 +441,14 @@ static int user_main(int argc, char *argv[])
|
|||||||
check_test_memory_usage();
|
check_test_memory_usage();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_SCHED_WAITPID
|
||||||
|
/* Verify pthread_exit() and pthread_self() */
|
||||||
|
|
||||||
|
printf("\nuser_main: pthread_exit() test\n");
|
||||||
|
pthread_exit_test();
|
||||||
|
check_test_memory_usage();
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Verify pthreads rwlock interfaces */
|
/* Verify pthreads rwlock interfaces */
|
||||||
|
|
||||||
printf("\nuser_main: pthread_rwlock test\n");
|
printf("\nuser_main: pthread_rwlock test\n");
|
||||||
|
114
testing/ostest/pthread_exit.c
Normal file
114
testing/ostest/pthread_exit.c
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* apps/testing/ostest/pthread_exit.c
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "ostest.h"
|
||||||
|
|
||||||
|
#ifdef CONFIG_SCHED_WAITPID
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define PRIORITY 100
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void *pthread_exit_thread(FAR void *parameter)
|
||||||
|
{
|
||||||
|
unsigned me = (unsigned)pthread_self();
|
||||||
|
|
||||||
|
printf("pthread_exit_thread %u: Sleeping for 10 second\n", me);
|
||||||
|
sleep(5);
|
||||||
|
printf("pthread_exit_thread %u: Still running...\n", me);
|
||||||
|
sleep(5);
|
||||||
|
printf("pthread_exit_thread %u: Exiting\n", me);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pthread_exit_main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
pthread_t child;
|
||||||
|
#ifdef SDCC
|
||||||
|
pthread_attr_t attr;
|
||||||
|
#endif
|
||||||
|
unsigned me = (unsigned)pthread_self();
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
printf("pthread_exit_main %u: Starting pthread_exit_thread\n", me);
|
||||||
|
#ifdef SDCC
|
||||||
|
pthread_attr_init(&attr);
|
||||||
|
ret = pthread_create(&child, &attr, pthread_exit_thread, NULL);
|
||||||
|
#else
|
||||||
|
ret = pthread_create(&child, NULL, pthread_exit_thread, NULL);
|
||||||
|
#endif
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
printf("Thread creation failed, return code %d", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("pthread_exit_main %u: Sleeping for 5 seconds\n", me);
|
||||||
|
fflush(stdout);
|
||||||
|
sleep(5);
|
||||||
|
|
||||||
|
printf("pthread_exit_main %u: Calling pthread_exit()\n", me);
|
||||||
|
pthread_exit(NULL);
|
||||||
|
|
||||||
|
printf("pthread_exit_main %u: ERROR: Still running\n", me);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void pthread_exit_test(void)
|
||||||
|
{
|
||||||
|
int statloc;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = task_create("pthread_exit", PRIORITY, STACKSIZE, pthread_exit_main,
|
||||||
|
NULL);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
printf("pthread_exit_test: ERROR task_create Failed\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("pthread_exit_test: Started pthread_exit_main at PID=%d\n",
|
||||||
|
ret);
|
||||||
|
waitpid((pid_t)ret, &statloc, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_SCHED_WAITPID */
|
Loading…
x
Reference in New Issue
Block a user