Thread SlotS

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
JoVM
Posts: 89
Joined: Thu Mar 12, 2015 12:13 pm

Thread SlotS

Post by JoVM »

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 );
}
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Thread SlotS

Post by Giovanni »

it is roughly equivalent to chThdWait().

Giovanni
JoVM
Posts: 89
Joined: Thu Mar 12, 2015 12:13 pm

Re: Thread SlotS

Post by JoVM »

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
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Thread SlotS

Post by Giovanni »

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

Re: Thread SlotS

Post by JoVM »

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?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Thread SlotS

Post by Giovanni »

It means that the thread is terminated.

Giovanni
Post Reply