All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Gerum <rpm@xenomai.org>
To: Jan Kiszka <jan.kiszka@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] What returns rt_task_self in relation to	rt_task_create
Date: Wed, 22 Nov 2006 13:52:20 +0100	[thread overview]
Message-ID: <1164199940.5006.270.camel@domain.hid> (raw)
In-Reply-To: <45643CC4.1000201@domain.hid>

On Wed, 2006-11-22 at 13:04 +0100, Jan Kiszka wrote:
> M. Koehrer wrote:
> > Hi all,
> > 
> > I have a simple question concerning the Xenomai native API:
> > According to the API documentation, rt_task_self returns the 
> > address of the caller's task descriptor.
> > I have now written the following (simple application):
> > ---------- START ----------
> > #include <stdio.h>
> > #include <sys/mman.h>
> > #include <native/task.h>
> > 
> > RT_TASK task_desc;
> > 
> > void mytask(void *cookie)
> > {
> >     RT_TASK *tsk = rt_task_self();
> >     printf("rt_task_self  %p\n"
> >            "task_desc     %p\n", tsk, &task_desc);
> > }
> > 
> > int main(void)
> > {
> >     mlockall(MCL_CURRENT|MCL_FUTURE);
> > 
> >     rt_task_create(&task_desc, "mytaskname", 0, 80, T_JOINABLE);
> >     rt_task_start(&task_desc, &mytask, NULL);
> > 
> >     rt_task_join(&task_desc);
> > 
> >     return 0;
> > }
> > ------------ END -----------
> > 
> > I expect now that rt_task_self() returns exactly the address of the task_desc.
> > However, a different address is returned. 
> > The output of the application from above is:
> > rt_task_self  0x804a050
> > task_desc     0x8049878
> > 
> > How are those addresses related - how can I find out the descriptor address 
> > used for rt_task_create() at runtime?
> 
> The documentation is not precise enough here: what you obtain from
> rt_task_self is /some/ task descriptor for the currently running task,
> it is not a reference to the same piece of memory containing the task
> descriptor. Check the library implementation for further insights.
> 

A descriptor should always be seen as a reference to an object, not as
the object itself. Said differently, there is no such thing as a
main/unique/specific descriptor for any given object. The doc says
exactly that: you get a valid descriptor to the task by calling
rt_task_self(), but nothing says that this ought to be the unique way of
referencing it. It's merely a kind of pointer, although it's not
implemented as a C pointer. This is the reason why the storage address
of the descriptor itself has no value per se, and nothing should be
derived from it. This is what makes objects shareable betwen kernel and
user-space seamlessly from the user POV.

> > 
> > Background of the question:
> > I want to write an application that uses a couple of similar tasks.
> > I have to store some task-specific information (internal states...).
> > Now I am looking for a simple way to get this information at runtime from my task
> > by calling rt_task_self() (or something similar) to use this address to reach my
> > additional information.
> 
> If you are on NPTL glibc, set up a __thread variable for the per-thread
> information. It will always contain the thread-related data that you
> can, e.g., fill in during the thread routine's prologue.
> 
> Jan
> 
> _______________________________________________
> Xenomai-help mailing list
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help
-- 
Philippe.




  reply	other threads:[~2006-11-22 12:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-22 11:38 [Xenomai-help] What returns rt_task_self in relation to rt_task_create M. Koehrer
2006-11-22 12:04 ` Jan Kiszka
2006-11-22 12:52   ` Philippe Gerum [this message]
2006-11-22 13:14     ` Jan Kiszka
2006-11-22 14:00       ` Philippe Gerum
2006-11-22 14:03         ` Gilles Chanteperdrix
2006-11-22 14:22           ` Philippe Gerum
2006-11-22 16:34             ` Gilles Chanteperdrix
2006-11-22 17:03               ` Philippe Gerum
2006-11-22 17:38                 ` Gilles Chanteperdrix
2006-11-22 18:33                   ` Philippe Gerum
2006-11-22 14:16         ` Re: [Xenomai-help] What returns rt_task_self in M. Koehrer
2006-11-22 14:33           ` Jan Kiszka
2006-11-22 14:49           ` Philippe Gerum
2006-11-22 13:09 ` [Xenomai-help] What returns rt_task_self in relation to rt_task_create Philippe Gerum
2006-11-22 13:48   ` [Xenomai-help] What returns rt_task_self in relation tort_task_create Daniel Schnell
2006-11-22 14:06     ` Jan Kiszka
2006-11-22 14:16     ` Philippe Gerum
2006-11-22 14:23       ` Philippe Gerum

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=1164199940.5006.270.camel@domain.hid \
    --to=rpm@xenomai.org \
    --cc=jan.kiszka@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.