rt_task_delete trouble
Hello,
i'm a newbie with xenomai.
My problem is, if a rt task will delete with rt_task_delete, than the progam hangs.
here is my sample
----------------------------------
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>
#include <native/mutex.h>
#include <native/task.h>
#include <native/types.h>
#include <rtdk.h>
RT_TASK task_waiter, task_worker;
volatile int task_waiter_flag = 0;
#define DELAYS(x) (x * 1000 * 1000 * 1000)
#define DELAYMS(x) (x * 1000 * 1000)
void delaysec(unsigned int sec)
{
RTIME delay = DELAYS(sec);
rt_task_sleep( delay );
}void task_waiter_do(void *data)
{
rt_printf("task_waiter_do started\n");
while(task_waiter_flag == 0)
; // rt_task_sleep( DELAYMS(1) );
rt_printf("task_waiter_do finished\n");
}void task_worker_do(void *data)
{
int rval;
rt_printf("task_worker_do started\n");
delaysec(1);
rt_printf("task_worker_do suspend waiter\n");
rval = rt_task_suspend(&task_waiter);
rt_printf("task_worker_do suspend:%d\n", rval);
delaysec(1);
rt_printf("task_worker_do delete waiter\n");
rval = rt_task_delete(&task_waiter);
rt_printf("task_worker_do delete:%d\n", rval);
delaysec(1);
while(task_waiter_flag == 0)
rt_task_sleep( DELAYMS(10) );
rt_printf("task_worker_do finished\n");
}int main(int argc, char **argv)
{
int rval;
mlockall(MCL_CURRENT|MCL_FUTURE);
printf("Starting\n");
rt_print_auto_init(1);
rval = rt_task_create(&task_worker, "worker", 0, 80, 0);
if (rval == 0) {
rval = rt_task_create(&task_waiter, "waiter", 0, 30, 0);
rval = rt_task_start(&task_worker, &task_worker_do, NULL);
if (rval == 0) {
rval = rt_task_start(&task_waiter, &task_waiter_do, NULL);
if (rval == 0) {
printf("Working\n");
}
else
rt_printf("rt_task_suspend failed(%d)", rval);
}
else
rt_printf("rt_task_start failed(%d)", rval);
}
else
rt_printf("rt_task_create failed(%d)", rval);
printf("Finsihed <press any key>\n");
getchar();
task_waiter_flag = 1;
usleep(100000);
return 0;
}----------------------------------
the task task_worker_do will hang after rt_task_delete. Why ? if i add a sleep into task_waiter_do, the sample work correct. What can i do, to solve this.
Thanks
greetings
Johann
Signature · 21 lines
Mit freundlichen Grüßen, best regards
Johann Obermayr
Software Entwicklung
________________________________________________
SIGMATEK GmbH& Co KG
Sigmatekstraße 1
5112 Lamprechtshausen
Österreich / Austria
Tel. : +43 / 6274/ 43 21-0 (Durchwahl leider nicht möglich)
Fax : +43 / 6274/ 43 21-18 (bzw 300 im Werk 2 )
E-Mail:[email protected]
http://www.sigmatek-automation.com
****************************Please note:********************************
This email and all attachments are confidential and intended solely for
the person or entity to whom it is addressed. If you are not the named
addressee you must not make this email and all attachments accessible
to any other person. If you have received this email in error please
delete it together with all attachments.
************************************************************************Quoted 7 lines · Johann Obermayr
void
task_waiter_do(void *data){ rt_printf("task_waiter_do started\n"); while(task_waiter_flag == 0) ; // rt_task_sleep( DELAYMS(1) ); rt_printf("task_waiter_do finished\n"); }
What happens if you uncomment the rt_task_sleep here ?
Could you please give us some more information:
http://www.xenomai.org/index.php/Request_for_information
Do you have priority coupling enabled?
Signature · 1 line
Gilles.
Quoted 11 lines · Gilles Chanteperdrix
Quoted 7 lines · Johann Obermayr
void
task_waiter_do(void *data){ rt_printf("task_waiter_do started\n"); while(task_waiter_flag == 0) ; // rt_task_sleep( DELAYMS(1) ); rt_printf("task_waiter_do finished\n"); }What happens if you uncomment the
rt_task_sleephere ?
Given how often users make this mistake, should we enable the watchdog by default?
Jan
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Gilles Chanteperdrix
Quoted 7 lines · Johann Obermayr
void
task_waiter_do(void *data){ rt_printf("task_waiter_do started\n"); while(task_waiter_flag == 0) ; // rt_task_sleep( DELAYMS(1) ); rt_printf("task_waiter_do finished\n"); }
Quoted 7 lines
Quoted 2 lines
What happens if you uncomment the
rt_task_sleephere ?Given how often users make this mistake, should we enable the watchdog by default?
From my point of view, however strange this example is, it should work
with root thread priority coupling enabled.
Signature · 1 line
Gilles.
Am 11.03.2011 09:51, schrieb Gilles Chanteperdrix:
Quoted 9 lines
Quoted 7 lines · Johann Obermayr
void
task_waiter_do(void *data){ rt_printf("task_waiter_do started\n"); while(task_waiter_flag == 0) ; // rt_task_sleep( DELAYMS(1) ); rt_printf("task_waiter_do finished\n"); }What happens if you uncomment the
rt_task_sleephere ?
we have some shared code from another RT OS.
And in this code there are some while(hw_state) ; loops.
Quoted 4 lines
Could you please give us some more information:
http://www.xenomai.org/index.php/Request_for_informationDo you have priority coupling enabled?
Yes.
We use xenomai 2.5.5.2 and linux kernel 2.6.32.15. gcc 4.3.3
Here you have some more details.
a kernel module have a watchdog checker for some 'user-tasks' if a 'user-task' have a while loop, than the kernel module will suspend the user-task and call also the mayday function.
But on some other errorhandling, we have a high priortity watchdog task control the 'user'-tasks. On error the watchdog task suspend all user-tasks. (this work correct)
Than the watchdog-task switch off the user-task watchdog.
Make errorhandling and some other function (dump user-task stack)
Than the watchdog task will delete some user-task.
But if a user-task is in a while loop, the system hangs.
in user mode we have no mayday function.
it's look like, that when watchdog-task call rt_task_delete(user_task) , the user_task continue running. Is this so ?
Thanks
Jimmy
Signature · 21 lines
Mit freundlichen Grüßen, best regards
Johann Obermayr
Software Entwicklung
________________________________________________
SIGMATEK GmbH& Co KG
Sigmatekstraße 1
5112 Lamprechtshausen
Österreich / Austria
Tel. : +43 / 6274/ 43 21-0 (Durchwahl leider nicht möglich)
Fax : +43 / 6274/ 43 21-18 (bzw 300 im Werk 2 )
E-Mail: [email protected]
http://www.sigmatek-automation.com
****************************Please note:********************************
This email and all attachments are confidential and intended solely for
the person or entity to whom it is addressed. If you are not the named
addressee you must not make this email and all attachments accessible
to any other person. If you have received this email in error please
delete it together with all attachments.
************************************************************************Quoted 9 lines · Johann Obermayr
Am 11.03.2011 09:51, schrieb Gilles Chanteperdrix:
Quoted 8 lines
Quoted 7 lines · Johann Obermayr
void
task_waiter_do(void *data){ rt_printf("task_waiter_do started\n"); while(task_waiter_flag == 0) ; // rt_task_sleep( DELAYMS(1) ); rt_printf("task_waiter_do finished\n"); }
Quoted 3 lines
Quoted 1 line
What happens if you uncomment the
rt_task_sleephere ?we have some shared code from another RT OS.
And in this code there are somewhile(hw_state); loops.
I just ask you to uncomment this line and run the test to see if it changes anything. We are in the process of trying and understanding the issue here... not fixing anything yet.
But from a general point of vieuw, code with unbounded busy waits with Xenomai will not fly for other reasons.
Signature · 1 line
Gilles.
Am 11.03.2011 09:58, schrieb Jan Kiszka:
Quoted 9 lines · Gilles Chanteperdrix
Quoted 8 lines
Quoted 7 lines · Johann Obermayr
void
task_waiter_do(void *data){ rt_printf("task_waiter_do started\n"); while(task_waiter_flag == 0) ; // rt_task_sleep( DELAYMS(1) ); rt_printf("task_waiter_do finished\n"); }
Quoted 7 lines
Quoted 2 lines
What happens if you uncomment the
rt_task_sleephere ?Given how often users make this mistake, should we enable the watchdog by default?
Jan
We have a watchdog, and your watchdod-task suspend the user-task (task_waiter_do). the sample show this problem.
The task_worker_do is a watchdog. he control some other 'user-task'. In your project, the watchdog startup the watchdog-task.
the task_worker_do suspend the user-task.
the task_worker_do will delete the user-task.
if the user-task have only while(1); than the machine will hang. if the user-task have in the while a sleep or other function, the task_worker_do can delete the task_waiter, and all work correct.
Jimmy
Signature · 21 lines
Mit freundlichen Grüßen, best regards
Johann Obermayr
Software Entwicklung
________________________________________________
SIGMATEK GmbH& Co KG
Sigmatekstraße 1
5112 Lamprechtshausen
Österreich / Austria
Tel. : +43 / 6274/ 43 21-0 (Durchwahl leider nicht möglich)
Fax : +43 / 6274/ 43 21-18 (bzw 300 im Werk 2 )
E-Mail: [email protected]
http://www.sigmatek-automation.com
****************************Please note:********************************
This email and all attachments are confidential and intended solely for
the person or entity to whom it is addressed. If you are not the named
addressee you must not make this email and all attachments accessible
to any other person. If you have received this email in error please
delete it together with all attachments.
************************************************************************Am 11.03.2011 09:51, schrieb Gilles Chanteperdrix:
Quoted 9 lines
Quoted 7 lines · Johann Obermayr
void
task_waiter_do(void *data){ rt_printf("task_waiter_do started\n"); while(task_waiter_flag == 0) ; // rt_task_sleep( DELAYMS(1) ); rt_printf("task_waiter_do finished\n"); }What happens if you uncomment the
rt_task_sleephere ?
it work correct, if rt_task_sleep is uncommented.
Quoted 4 lines
Could you please give us some more information:
http://www.xenomai.org/index.php/Request_for_informationDo you have priority coupling enabled?
Yes.
Jimmy
Signature · 21 lines
Mit freundlichen Grüßen, best regards
Johann Obermayr
Software Entwicklung
________________________________________________
SIGMATEK GmbH& Co KG
Sigmatekstraße 1
5112 Lamprechtshausen
Österreich / Austria
Tel. : +43 / 6274/ 43 21-0 (Durchwahl leider nicht möglich)
Fax : +43 / 6274/ 43 21-18 (bzw 300 im Werk 2 )
E-Mail: [email protected]
http://www.sigmatek-automation.com
****************************Please note:********************************
This email and all attachments are confidential and intended solely for
the person or entity to whom it is addressed. If you are not the named
addressee you must not make this email and all attachments accessible
to any other person. If you have received this email in error please
delete it together with all attachments.
************************************************************************Quoted 16 lines · Johann Obermayr
We use xenomai 2.5.5.2 and linux kernel 2.6.32.15. gcc 4.3.3
Here you have some more details.
a kernel module have a watchdog checker for some 'user-tasks' if a 'user-task' have a while loop, than the kernel module will suspend the user-task and call also the mayday function.But on some other errorhandling, we have a high priortity watchdog task control the 'user'-tasks.
On error the watchdog task suspend all user-tasks. (this work correct) Than the watchdog-task switch off the user-task watchdog. Make errorhandling and some other function (dump user-task stack) Than the watchdog task will delete some user-task.
But if a user-task is in a while loop, the system hangs.
in user mode we have no mayday function.
Quoted 1 line
From my point of view, you should be using the watchdog provided by
Xenomai. Did you notice that in your application, you can register a signal handler to handle the watchdog signal? This would allow you to use the watchdog provided by Xenomai to handle tasks blocked in infinite loops. Then use your watchdog to handle other cases.
See the example at examples/native/sigdebug.c
Quoted 3 lines
it's look like, that when watchdog-task call
rt_task_delete(user_task), theuser_taskcontinue running.
Is this so ?
Yes, this is probably the reason. The thing is that the watchdog task calling rt_task_delete calls pthread_cancel, which causes a switch to secondary mode. What I do not understand, however, is that since you have priority coupling enabled, it should work. So, I have to reproduce this case to understand. But actually, now that I think about it, Wolfgang signalled the same issue with pthread_cancel and the posix skin a long time ago, I looked at it, and I seem to remember that after investigation, it could not work.
Signature · 1 line
Gilles.