All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Problem with pthread_cond_wait
@ 2009-12-03 12:07 Soboljew, Patrick
  2009-12-03 13:15 ` Gilles Chanteperdrix
  2009-12-03 23:58 ` Gilles Chanteperdrix
  0 siblings, 2 replies; 8+ messages in thread
From: Soboljew, Patrick @ 2009-12-03 12:07 UTC (permalink / raw)
  To: xenomai

Hello all,

I have a strange problem concerning the posix skin of xenomai (Ver.
2.4.9.1). Whenever two or more threads call 'pthread_cond_wait' and I
want to interrupt the program with SIGINT (CTRL-c) only the main thread
and the first thread that called 'pthread_cond_wait' get the signal. The
remaining threads are not interrupted so I have created some zombies
here. I discovered this problem when I tried to debug some code with the
ACE/TAO Framework which calls these functions in a similar way. The
debugger also has problems to interrupt these threads.

The small code example illustrates what I did.

Has anyone an idea what exactly causes this problem?

Thanks for any help
Patrick Soboljew

======================================== Code Begin
======================================== 
#include <pthread.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


const int NUM_THREADS=2;
pthread_mutex_t Mutex;
pthread_cond_t  Condition;


void SetupRtThread()
{
#ifdef __XENO__
    int RetVal = 0;
    struct sched_param SParam;
    SParam.sched_priority = 1;
    int Policy = SCHED_FIFO;
    if ((RetVal = pthread_setschedparam(pthread_self(), Policy,
&SParam)) != 0)
    {
        printf("pthread_setschedparam: %s", strerror(RetVal));
        exit(RetVal);
    }
#endif
}


void *ThreadFunc(void *pData)
{
    SetupRtThread();
    int MyId = (int)pData;

    printf("Starting thread %d\n", MyId);

    pthread_mutex_lock(&Mutex);
    pthread_cond_wait(&Condition, &Mutex);
    pthread_mutex_unlock(&Mutex);

    pthread_exit(NULL);
}


int main (int /*argc*/, char** /*argv[]*/)
{
    mlockall(MCL_CURRENT | MCL_FUTURE);
    SetupRtThread();


    pthread_t threads[NUM_THREADS];


    // Initialize mutex and condition variable objects
    pthread_mutex_init(&Mutex, NULL);
    pthread_cond_init (&Condition, NULL);


    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

    for (int i=0; i<NUM_THREADS; ++i)
    {
        pthread_create(&threads[i], &attr, ThreadFunc, (void *)i);
    }

    /* Wait for all threads to complete */
    for (int i=0; i<NUM_THREADS; i++)
    {
        pthread_join(threads[i], NULL);
    }
    printf ("Main(): Waited on %d  threads. Done.\n", NUM_THREADS);

    /* Clean up and exit */
    pthread_attr_destroy(&attr);
    pthread_mutex_destroy(&Mutex);
    pthread_cond_destroy(&Condition);
    pthread_exit(NULL);

}

======================================== Code End
============================================ 


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-12-06 17:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-03 12:07 [Xenomai-help] Problem with pthread_cond_wait Soboljew, Patrick
2009-12-03 13:15 ` Gilles Chanteperdrix
2009-12-03 23:58 ` Gilles Chanteperdrix
2009-12-04  9:46   ` Soboljew, Patrick
2009-12-04  9:59   ` Philippe Gerum
2009-12-04 10:09     ` Gilles Chanteperdrix
2009-12-04 10:26       ` Gilles Chanteperdrix
2009-12-06 17:22       ` Philippe Gerum

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.