* [Xenomai-help] Problem with mutexes in daemon
@ 2009-04-22 9:41 Roman Pisl
2009-04-22 9:57 ` Gilles Chanteperdrix
0 siblings, 1 reply; 4+ messages in thread
From: Roman Pisl @ 2009-04-22 9:41 UTC (permalink / raw)
To: xenomai
[-- Attachment #1: Type: text/plain, Size: 419 bytes --]
Hello,
I'm experiencing weird behavior with mutexes in a daemon application.
After daemon() is called, unnamed mutexes fail on call
rt_mutex_release() with -EPERM. Everything is ok for named mutexes.
Is there something special with daemon and unnamed mutexes - should all
have name? Or is it a bug? I'm using kernel 2.6.28 and Xenomai 2.4.6.1.
Example showing this problem is attached.
Thank you for help,
Roman
[-- Attachment #2: daemon.c --]
[-- Type: text/plain, Size: 3313 bytes --]
#include <stdio.h>
#include <stdbool.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>
#include <native/task.h>
#include <native/cond.h>
#include <native/mutex.h>
#include <native/timer.h>
RT_TASK demo_task;
RT_TASK main_task;
RT_MUTEX mutex;
RT_MUTEX shut_mutex;
RT_COND shut_cond;
#define TRUE 1
#define FALSE 0
bool terminated = FALSE;
bool terminated2 = FALSE;
void demo(void *arg)
{
int ret;
RTIME now, previous;
rt_task_set_periodic(NULL, TM_NOW, 1000000000);
previous = rt_timer_read();
while (!terminated2) {
rt_task_wait_period(NULL);
now = rt_timer_read();
printf("DT: Time since last turn: %ld.%06ld ms\n",
(long)(now - previous) / 1000000,
(long)(now - previous) % 1000000);
previous = now;
if (ret = rt_mutex_acquire(&mutex, TM_INFINITE))
printf("DT: rt_mutex_acquire() failed %i\n", ret);
rt_task_sleep(1000000);
if (ret = rt_mutex_release(&mutex))
printf("DT: rt_mutex_release() failed %i\n", ret);
}
if (ret = rt_mutex_acquire(&shut_mutex, TM_INFINITE))
printf("DT: rt_mutex_acquire() before cond failed %i\n", ret);
if (ret = rt_cond_signal(&shut_cond))
printf("DT: rt_cond_signal() failed %i\n", ret);
if (ret = rt_mutex_release(&shut_mutex))
printf("DT: rt_mutex_release() after cond failed %i\n", ret);
}
void catch_signal(int sig)
{
terminated = TRUE;
}
int main(int argc, char* argv[])
{
int ret;
//when daemon - problems with unnamed mutexes
//without daemon everything ok
daemon(1, 1);
if (ret = rt_mutex_create(&mutex, NULL))
{
printf("Error creating mutex %i\n", ret);
return 0;
}
if (ret = rt_mutex_create(&shut_mutex, NULL))
{
printf("Error creating shut_mutex %i\n", ret);
return 0;
}
if (ret = rt_cond_create(&shut_cond, NULL))
{
printf("Error creating cond%i\n", ret);
return 0;
}
signal(SIGTERM, catch_signal);
signal(SIGINT, catch_signal);
mlockall(MCL_CURRENT|MCL_FUTURE);
if (ret = rt_task_shadow(&main_task, "main", 90, 0))
printf("rt_task_shadow() failed %i\n", ret);
if (ret = rt_task_create(&demo_task, "trivial", 0, 99, 0))
printf("rt_task_create() failed %i\n", ret);
rt_task_start(&demo_task, &demo, NULL);
while (!terminated)
{
if (ret = rt_mutex_acquire(&mutex, TM_INFINITE))
printf("MT: rt_mutex_acquire() failed, %i\n", ret);
rt_task_sleep(1000000);
printf("sleep\n");
if (ret = rt_mutex_release(&mutex))
printf("MT: rt_mutex_release() failed %i\n", ret);
rt_task_sleep(1000000000);
}
printf("Finished...\n");
if (ret = rt_mutex_acquire(&shut_mutex, TM_INFINITE))
printf("MT: rt_mutex_acquire() before cond failed %i\n", ret);
terminated2 = TRUE;
if (ret = rt_cond_wait(&shut_cond, &shut_mutex, TM_INFINITE))
printf("MT: rt_cond_signal() failed %i\n", ret);
if (ret = rt_mutex_release(&shut_mutex))
printf("MT: rt_mutex_release() after cond failed %i\n", ret);
rt_task_delete(&demo_task);
rt_mutex_delete(&mutex);
rt_mutex_delete(&shut_mutex);
rt_cond_delete(&shut_cond);
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai-help] Problem with mutexes in daemon
2009-04-22 9:41 [Xenomai-help] Problem with mutexes in daemon Roman Pisl
@ 2009-04-22 9:57 ` Gilles Chanteperdrix
2009-04-22 10:34 ` Roman Pisl
0 siblings, 1 reply; 4+ messages in thread
From: Gilles Chanteperdrix @ 2009-04-22 9:57 UTC (permalink / raw)
To: Roman Pisl; +Cc: xenomai
Roman Pisl wrote:
> Hello,
> I'm experiencing weird behavior with mutexes in a daemon application.
> After daemon() is called, unnamed mutexes fail on call
> rt_mutex_release() with -EPERM. Everything is ok for named mutexes.
>
> Is there something special with daemon and unnamed mutexes - should all
> have name? Or is it a bug? I'm using kernel 2.6.28 and Xenomai 2.4.6.1.
>
> Example showing this problem is attached.
Unnamed mutexes are local to a process. Since forking results in a
different process, mutexes are not preserved.
Yes, Xenomai behaviour is not intuitive, but fixing this requires
internal changes.
--
Gilles.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai-help] Problem with mutexes in daemon
2009-04-22 9:57 ` Gilles Chanteperdrix
@ 2009-04-22 10:34 ` Roman Pisl
2009-04-22 11:57 ` Gilles Chanteperdrix
0 siblings, 1 reply; 4+ messages in thread
From: Roman Pisl @ 2009-04-22 10:34 UTC (permalink / raw)
To: Gilles Chanteperdrix; +Cc: xenomai
Gilles Chanteperdrix napsal(a):
> Roman Pisl wrote:
>> Hello,
>> I'm experiencing weird behavior with mutexes in a daemon application.
>> After daemon() is called, unnamed mutexes fail on call
>> rt_mutex_release() with -EPERM. Everything is ok for named mutexes.
>>
>> Is there something special with daemon and unnamed mutexes - should all
>> have name? Or is it a bug? I'm using kernel 2.6.28 and Xenomai 2.4.6.1.
>>
>> Example showing this problem is attached.
>
> Unnamed mutexes are local to a process. Since forking results in a
> different process, mutexes are not preserved.
>
> Yes, Xenomai behaviour is not intuitive, but fixing this requires
> internal changes.
>
I understand, but daemon() is the first call and everything is done in
the new forked process.
What is the best solution for now? Is everything except unnamed mutexes
supposed to work well in daemon or should I cancel the concept of daemon
at all?
Roman
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai-help] Problem with mutexes in daemon
2009-04-22 10:34 ` Roman Pisl
@ 2009-04-22 11:57 ` Gilles Chanteperdrix
0 siblings, 0 replies; 4+ messages in thread
From: Gilles Chanteperdrix @ 2009-04-22 11:57 UTC (permalink / raw)
To: Roman Pisl; +Cc: xenomai
Roman Pisl wrote:
> Gilles Chanteperdrix napsal(a):
>> Roman Pisl wrote:
>>> Hello,
>>> I'm experiencing weird behavior with mutexes in a daemon application.
>>> After daemon() is called, unnamed mutexes fail on call
>>> rt_mutex_release() with -EPERM. Everything is ok for named mutexes.
>>>
>>> Is there something special with daemon and unnamed mutexes - should all
>>> have name? Or is it a bug? I'm using kernel 2.6.28 and Xenomai 2.4.6.1.
>>>
>>> Example showing this problem is attached.
>> Unnamed mutexes are local to a process. Since forking results in a
>> different process, mutexes are not preserved.
>>
>> Yes, Xenomai behaviour is not intuitive, but fixing this requires
>> internal changes.
>>
>
> I understand, but daemon() is the first call and everything is done in
> the new forked process.
>
> What is the best solution for now? Is everything except unnamed mutexes
> supposed to work well in daemon or should I cancel the concept of daemon
> at all?
Yes, what you are doing is supposed to work, I did not look at your
code, I thought you were expecting to be able to create the mutex in a
process and use it in its child.
On what platform do you get these issues ?
--
Gilles.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-04-22 11:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-22 9:41 [Xenomai-help] Problem with mutexes in daemon Roman Pisl
2009-04-22 9:57 ` Gilles Chanteperdrix
2009-04-22 10:34 ` Roman Pisl
2009-04-22 11:57 ` 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.