All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Mixing skin calls (cancellation points)
@ 2010-07-06 18:36 Steve Deiters
  2010-07-06 18:41 ` Gilles Chanteperdrix
  2010-07-07 12:50 ` Gilles Chanteperdrix
  0 siblings, 2 replies; 11+ messages in thread
From: Steve Deiters @ 2010-07-06 18:36 UTC (permalink / raw)
  To: xenomai

Is it in general valid to mix calls from different skins?  In
particular, can I expect the native skin calls to work as POSIX
cancellation points?  For example, if I have a POSIX thread with a
pthread_t identifier which I know calls rt_cond_wait somewhere, will it
work as a cancellation point when I call pthread_cancel?

The example program attached will not cancel if I have CANCEL_DEFERRED
defined as 1 at the top, which sets the cancel type to deferred.  This
is on a PowerPC with Xenomai 2.5.3.  I think this worked with Xenomai
2.4.10.


--------


#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <native/task.h>
#include <native/cond.h>

#define CANCEL_DEFERRED 1

RT_MUTEX mutex;
RT_COND cond;
pthread_t thread;

void *entry(void *cookie)
{
   fprintf(stderr, "Starting thread\n");

#if CANCEL_DEFERRED
   pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
#else
   pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
#endif

   rt_mutex_acquire(&mutex, TM_INFINITE);
   rt_cond_wait(&cond, &mutex, TM_INFINITE);
   rt_mutex_release(&mutex);

   return NULL;
}

int main(int argc, char **argv)
{
   int ret;
   pthread_attr_t attr;

   if((ret = rt_mutex_create(&mutex, NULL)))
   {
      errno = -ret;
      perror("rt_mutex_create");
      exit(EXIT_FAILURE);
   }

   if((ret = rt_cond_create(&cond, NULL)))
   {
      errno = -ret;
      perror("rt_cond_create");
      exit(EXIT_FAILURE);
   }

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

   if(pthread_create(&thread, &attr, entry, NULL))
   {
      perror("pthread_create");
      exit(EXIT_FAILURE);
   }

   fprintf(stderr, "Sleeping 5 seconds\n");
   sleep(5);
   fprintf(stderr, "Woke up, cancelling thread\n");

   pthread_cancel(thread);
   pthread_join(thread, NULL);

   return 0;
}


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

end of thread, other threads:[~2010-08-01 22:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-06 18:36 [Xenomai-help] Mixing skin calls (cancellation points) Steve Deiters
2010-07-06 18:41 ` Gilles Chanteperdrix
2010-07-06 19:03   ` Steve Deiters
2010-07-06 19:15     ` Gilles Chanteperdrix
2010-07-07 12:50 ` Gilles Chanteperdrix
2010-07-07 15:20   ` Steve Deiters
2010-07-07 16:36     ` Gilles Chanteperdrix
2010-07-07 16:55       ` Steve Deiters
2010-07-07 17:14         ` Gilles Chanteperdrix
2010-07-07 17:25         ` Gilles Chanteperdrix
2010-08-01 22:11           ` Gilles Chanteperdrix

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.