xref: /nrf52832-nimble/rt-thread/examples/libc/ex6.c (revision 104654410c56c573564690304ae786df310c91fc)
1*10465441SEvalZero #include <errno.h>
2*10465441SEvalZero #include <stdio.h>
3*10465441SEvalZero #include <string.h>
4*10465441SEvalZero #include <pthread.h>
5*10465441SEvalZero #include <unistd.h>
6*10465441SEvalZero 
7*10465441SEvalZero #define usleep rt_thread_sleep
8*10465441SEvalZero 
test_thread(void * v_param)9*10465441SEvalZero static void *test_thread(void *v_param) {
10*10465441SEvalZero 	return NULL;
11*10465441SEvalZero }
12*10465441SEvalZero 
libc_ex6(void)13*10465441SEvalZero int libc_ex6(void) {
14*10465441SEvalZero 	unsigned long count;
15*10465441SEvalZero 
16*10465441SEvalZero 	setvbuf(stdout, NULL, _IONBF, 0);
17*10465441SEvalZero 
18*10465441SEvalZero 	for (count = 0; count < 2000; ++count) {
19*10465441SEvalZero 		pthread_t thread;
20*10465441SEvalZero 		int status;
21*10465441SEvalZero 
22*10465441SEvalZero 		status = pthread_create(&thread, NULL, test_thread, NULL);
23*10465441SEvalZero 		if (status != 0) {
24*10465441SEvalZero 			printf("status = %d, count = %lu: %s\n", status, count, strerror(
25*10465441SEvalZero 					errno));
26*10465441SEvalZero 			return 1;
27*10465441SEvalZero 		} else {
28*10465441SEvalZero 			printf("count = %lu\n", count);
29*10465441SEvalZero 		}
30*10465441SEvalZero 		/* pthread_detach (thread); */
31*10465441SEvalZero 		pthread_join(thread, NULL);
32*10465441SEvalZero 		usleep(10);
33*10465441SEvalZero 	}
34*10465441SEvalZero 	return 0;
35*10465441SEvalZero }
36*10465441SEvalZero #include <finsh.h>
37*10465441SEvalZero FINSH_FUNCTION_EXPORT(libc_ex6, example 6 for libc);
38