Skip to contentSkip to conversation

problem with rt_task_delete/pthread_cancel

Xenomai-help Tomas Kalibera 1 participant 1 message Apr 14, 2008

lore
Share & tools
lore
#0 lore raw

Hi,

I'm trying to terminate a program from a child task. The idea is that a joinable child task kills itself, unblocking its parent which exits the application. However, the program crashes when the child calls rt_task_delete.

Inspecting the core file by gdb shows this:

Program terminated with signal 11, Segmentation fault.
#0 0xb7f014cd in pthread_cancel () from /lib/tls/i686/cmov/libpthread.so.0

A simple program which triggers the problem is attached. Is this a bug, or the API should not be used in this way ?

Thanks,

Tomas

#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>

#include <native/task.h>
#include <rtdk.h>

RT_TASK child;

void child_body(void *cookie) {
int rc;

  fprintf(stderr,"In child..\n");

  rc=rt_task_delete(rt_task_self());
  if (rc!=0) {
    fprintf(stderr,"rt_task_delete returned %d\n");
  }

}

int main(int argc, char **argv) {

int rc;

  mlockall(MCL_CURRENT|MCL_FUTURE);
  
  rc=rt_task_create(&child,"ovmtask",0,11,T_JOINABLE);  
  if (rc!=0) {
    fprintf(stderr,"rt_task_create returned %d\n");
  }  

  rc=rt_task_start(&child,&child_body,NULL);
  if (rc!=0) {
    fprintf(stderr,"rt_task_start returned %d\n");
  }  

  rc=rt_task_join(&child);
  if (rc!=0) {
    fprintf(stderr,"rt_task_join returned %d\n");
  }  

return 0;
}