Threads stuck in kserel state

Saradhi Kothapalli saikothapalli at gmail.com
Tue Jun 24 07:12:47 UTC 2008


Hi

I am running FreeBSD 5.4 on my machine. When i run mpd on it, i see it stuck
in kserel state.
I have written a sample thread program to check whether its an mpd problem
or not.

Observations on the Sample test program:

I have created only one thread from the process, but the top output shows
total 3 entries.
Even when the thread has finished i see 2 entries that to one in kserel and
other in ksesig state.

Is the main process stuck in "kserel" state or is it an expected behavior?
Is it because of KSE the other thread is shown in top output? Is the state
"ksesig" signifies that it is waiting for an event to occur?


Thanks in advance for the help.

Regards
Saradhi


The Sample Test program:

#include <stdio.h>
#include <pthread.h>
#include <pdel/structs/structs.h>
#include <pdel/structs/type/array.h>
#include <pdel/util/typed_mem.h>
#include <pdel/util/pevent.h>
#include <pdel/util/paction.h>
#include <pdel/util/ghash.h>
#include <unistd.h>

pthread_mutex_t mutex;

static void
startFn(void * arg)
{
    printf("\n *** Thread Start Function *** \n");
    getchar();
    return;
}

static void
endFn(void * arg, int done)
{
    printf("\n *** Thread End Function *** \n");
    getchar();
    return;
}

static void
thrStart()
{
    struct paction * thr;
    uint32_t temp;

    if ( paction_start(&thr, &mutex, startFn, endFn, &temp) == -1 )
    {
        printf("\n *** Failed to start thread *** \n ");
        getchar();
    }
    return ;
}

int main()
{

    int ret = pthread_mutex_init(&mutex, NULL);
    if ( ret != 0 )
    {
        printf("\n *** Mutex initialization Failed *** \n");
        return -1;
    }

    printf("\n *** calling thread start *** \n ");
    getchar();

    thrStart();

    for ( ; ; )
    {
        sleep(1);
    }
    return 0;
}

THE TOP OUTPUT WITH THREAD DISPLAY TURNED ON:

When the thread is in existence (both during start and end function):
-----------------------------------------------------------------------------------------------------

18387 root      20    0  3384K  1760K ksesig   0:00  0.00%  0.00% thrd
18387 root      20    0  3384K  1760K kserel   0:00  0.00%  0.00% thrd
18387 root       5    0  3384K  1760K  ttyin    0:00  0.00%  0.00% thrd

After the thread execution is completed (the for loop):
---------------------------------------------------------
18387 root      20    0  3384K  1752K ksesig   0:00  0.00%  0.00% thrd
18387 root      20    0  3384K  1752K kserel   0:00  0.00%  0.00% thrd


More information about the freebsd-threads mailing list