ChibiOS public support forum for all topics not covered by a specific support forum.
Moderators: RoccoMarco , lbednarz , tfAteba
JoVM
Posts: 89 Joined: Thu Mar 12, 2015 12:13 pm
Post
by JoVM » Fri Aug 07, 2015 11:59 am
Is there a thread_join function in chibiOS 3.0 to do thread slots.
Code: Select all
static int thread_create( int client_fd ) { int ret, i; /* * Find in-active or finished thread slot */ for( i = 0; i < MAX_NUM_THREADS; i++ ) { if( threads[i].active == 0 ) break; if( threads[i].data.thread_complete == 1 ) { printf( " [ threading ] Cleaning up thread %d\n", i ); thread_join(threads[i].thread, NULL ); memset( &threads[i], 0, sizeof(pthread_info_t) ); break; } } if( i == MAX_NUM_THREADS ) return( -1 ); /* * Fill thread-info for thread */ memcpy( &threads[i].data, &base_info, sizeof(base_info) ); threads[i].active = 1; threads[i].data.client_fd = client_fd; if( ( ret = thread_create( &threads[i].thread, NULL, handle_ssl_connection, &threads[i].data ) ) != 0 ) { return( ret ); } return( 0 ); }
JoVM
Posts: 89 Joined: Thu Mar 12, 2015 12:13 pm
Post
by JoVM » Fri Aug 07, 2015 3:10 pm
Hi Giovanni,chThdWait() blocks the invoking thread. But this thread can't be blocked cause it's accepting connections. It manages a thread for each connection. If the handler thread is finished it frees a place in the list. Kr,Jo
Giovanni
Site Admin
Posts: 14891 Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times
Post
by Giovanni » Fri Aug 07, 2015 3:17 pm
pthread_join() is blocking as well, both do not block if the thread is already terminated. Giovanni
JoVM
Posts: 89 Joined: Thu Mar 12, 2015 12:13 pm
Post
by JoVM » Fri Aug 07, 2015 3:42 pm
tnx Giovanni,
Code: Select all
if (tp->p_state != CH_STATE_FINAL) { list_insert(currp, &tp->p_waiting); chSchGoSleepS(CH_STATE_WTEXIT); }CH_STATE_FINAL means the handler thread is cleaned?