All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Gerum <rpm@xenomai.org>
To: "Karch, Joshua" <jkarch@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] Segfault Problems with Message Queues
Date: Wed, 30 Apr 2008 20:36:21 +0200	[thread overview]
Message-ID: <4818BC25.8040305@domain.hid> (raw)
In-Reply-To: <51B669A8A7D2914E9AB2B3F40AC6553E646F5C@afsexc01.aurora.aero>

Karch, Joshua wrote:
> Hi All,
> 
> I tried implementing inter-task message queues and following the
> msg_queue.c example
> (http://www.xenomai.org/documentation/trunk/html/api/msg__queue_8c-example.html)
> and when I try to run the implementation after fixing some of the code
> (declaring fail() to printf an error, declaring int err, and changing
> &task_body to &consumer), I get the following error
> msg_queue[3897]: segfault at 00000000 eip b7cf8933 esp bf8dce04 error
> 6.  This comes out of the rt_queue_alloc function.
> 
> Has the implementation of message passing between userspace tasks
> changed?  Is there a more recent example?  My end goal is to send non
> blocking messages from one producer task at 50Hz to two reading tasks
> tasks with similar (though not exactly same) loop rates-- i.e. None of
> the tasks are synchronized, though they all run at about 50Hz.  Should I
> use message queues to do this?
>

Btw, that code skeleton was meant to be paired with a peer module in
kernel/userland that would create the queue. Nothing in this code does this; you
need to call rt_queue_create() at init to create the queue the consumer task
will bind to.

> Thank you,
> 
> Joshua Karch
> 
> Attached is the code I used..
> 
> #include <sys/mman.h>
> #include <stdio.h>
> #include <string.h>
> #include <native/task.h>
> #include <native/queue.h>
> 
> #define TASK_PRIO  99 /* Highest RT priority */
> #define TASK_MODE  0  /* No flags */
> #define TASK_STKSZ 0  /* Stack size (use default one) */
> 
> RT_QUEUE q_desc;
> 
> RT_TASK task_desc;
> 
> void fail()
> {
>         printf("error\n");
> }
> 
> 
> void consumer (void *cookie)
> 
> {
>     ssize_t len;
>     void *msg;
>     int err;
> 
>     /* Bind to a queue which has been created elsewhere, either in
>        kernel or user-space. The call will block us until such queue
>        is created with the expected name. The queue should have been
>        created with the Q_SHARED mode set, which is implicit when
>        creation takes place in user-space. */
> 
>     err = rt_queue_bind(&q_desc,"SomeQueueName",TM_INFINITE);
> 
>     if (err)
>         fail();
> 
>     /* Collect each message sent to the queue by the queuer() routine,
>        until the queue is eventually removed from the system by a call
>        to rt_queue_delete(). */
> 
>     while ((len = rt_queue_receive(&q_desc,&msg,TM_INFINITE)) > 0)
>         {
>         printf("received message> len=%d bytes, ptr=%p, s=%s\n",
>                len,msg,(const char *)msg);
>         rt_queue_free(&q_desc,msg);
>         }
> 
>     /* We need to unbind explicitly from the queue in order to
>        properly release the underlying memory mapping. Exiting the
>        process unbinds all mappings automatically. */
> 
>     rt_queue_unbind(&q_desc);
> 
>     if (len != -EIDRM)
>         /* We received some unexpected error notification. */
>         fail();
> 
>     /* ... */
> }
> 
> 
> int main (int argc, char *argv[])
> 
> {
>     static char *messages[] = { "hello", "world", NULL };
>     int n, len;
>     void *msg;
>     int err;
> 
>     mlockall(MCL_CURRENT|MCL_FUTURE);
> 
>     err = rt_task_create(&task_desc,
>                          "MyTaskName",
>                          TASK_STKSZ,
>                          TASK_PRIO,
>                          TASK_MODE);
>     if (!err)
>         rt_task_start(&task_desc,&consumer,NULL);
> 
>     /* ... */
> 
>     for (n = 0; messages[n] != NULL; n++)
>         {
>         len = strlen(messages[n]) + 1;
>         /* Get a message block of the right size. */
>         msg = rt_queue_alloc(&q_desc,len);
> 
>         if (!msg)
>             /* No memory available. */
>             fail();
> 
>         strcpy((char *)msg,messages[n]);
>         rt_queue_send(&q_desc,msg,len,Q_NORMAL);
>         }
> 
>     rt_task_delete(&task_desc);
> }
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Xenomai-help mailing list
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help


-- 
Philippe.


  parent reply	other threads:[~2008-04-30 18:36 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-22 22:46 [Xenomai-help] Xenomai serial port c++ code and / or xeno-- (xenomm-0.0.1) install problem Karch, Joshua
2008-04-23  0:12 ` Gilles Chanteperdrix
     [not found]   ` <51B669A8A7D2914E9AB2B3F40AC6553E646F15@domain.hid>
2008-04-23 13:58     ` [Xenomai-help] Xenomai serial port c++ code and / or xeno--(xenomm-0.0.1) " Gilles Chanteperdrix
2008-04-23 14:25       ` Karch, Joshua
2008-04-23 14:30         ` Gilles Chanteperdrix
2008-04-23 15:43           ` Karch, Joshua
2008-04-23 18:10             ` Gilles Chanteperdrix
     [not found]               ` <51B669A8A7D2914E9AB2B3F40AC6553E646F1D@afsexc01.aurora.aero>
2008-04-23 21:20                 ` [Xenomai-help] FW: " Karch, Joshua
2008-04-23 21:28                 ` [Xenomai-help] " Gilles Chanteperdrix
2008-04-23 21:36                   ` Karch, Joshua
2008-04-23 22:14                   ` [Xenomai-help] serial port overrun problem RT TASK Karch, Joshua
2008-04-24  6:43                     ` Gilles Chanteperdrix
2008-04-24  7:04                       ` Jan Kiszka
2008-04-24 14:16                         ` Karch, Joshua
2008-04-24 14:30                           ` Gilles Chanteperdrix
2008-04-24 16:58                             ` Karch, Joshua
2008-04-24 17:16                               ` Gilles Chanteperdrix
2008-04-24 22:37                                 ` [Xenomai-help] serial port overrun problem RT TASK geode latencies too high Karch, Joshua
2008-04-24 22:59                                   ` Gilles Chanteperdrix
2008-04-25 16:04                                     ` [Xenomai-help] Geode Latency Problem (Was: serial port overrun problem) Karch, Joshua
2008-04-25 16:12                                       ` Gilles Chanteperdrix
2008-04-24 13:59                       ` [Xenomai-help] serial port overrun problem RT TASK Karch, Joshua
2008-04-24 14:01                         ` Gilles Chanteperdrix
     [not found] ` <51B669A8A7D2914E9AB2B3F40AC6553E646F52@domain.hid>
     [not found]   ` <18454.9396.476627.446653@domain.hid>
     [not found]     ` <51B669A8A7D2914E9AB2B3F40AC6553E646F54@domain.hid>
     [not found]       ` <48162C69.6040101@domain.hid>
     [not found]         ` <18454.12323.344999.258031@domain.hid>
     [not found]           ` <51B669A8A7D2914E9AB2B3F40AC6553E646F55@domain.hid>
     [not found]             ` <48163EE7.5000604@domain.hid>
     [not found]               ` <18454.17297.451664.334250@domain.hid>
     [not found]                 ` <48164652.5090102@domain.hid>
     [not found]                   ` <2ff1a98a0804290252j1c9dc444kffb345ebaeb123d@domain.hid>
     [not found]                     ` <48187366.2060006@domain.hid>
2008-04-30 18:13                       ` [Xenomai-help] Segfault Problems with Message Queues Karch, Joshua
2008-04-30 18:31                         ` Philippe Gerum
2008-04-30 18:41                           ` Karch, Joshua
2008-04-30 18:48                             ` Philippe Gerum
2008-04-30 19:22                               ` Karch, Joshua
2008-04-30 18:36                         ` Philippe Gerum [this message]
2008-04-30 19:19                         ` Gilles Chanteperdrix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4818BC25.8040305@domain.hid \
    --to=rpm@xenomai.org \
    --cc=jkarch@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.