Philippe Gerum wrote:
> 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. 

The doc talks quite a lot about "_the_ task descriptor address" which
/may/ suggest to the reader that there is only one address. That this
cannot be the case becomes obvious when considering user/kernel or
cross-process usage. Still, clarification at some point can help to
avoid any future misinterpretation.

Suggestion (rt_task_self):

"Return the address of a descriptor for the current task.

Note: The returned descriptor address does not relate to the descriptor
address passed to rt_task_create or similar services."

Jan


PS: Who's supposed to free the descriptor allocated by rt_task_self?
Would some check for pthread_getspecific(__native_tskey) + free() on
task self-destruction make sense? Will not catch all cases, I know.

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Reply via email to