0

I am working on a big project that uses RTAI both in kernel and user spaces. I won't get into the details of the project, but here is briefly where a problem arises.

In user-space, my project provides a library used by other people to write some software. Those programs themselves may have RTAI real-time threads.

Now, some functions in RTAI require that their calling thread have already rt_thread_inited so if I want to use them in a function in the library, I need to temporarily make the calling thread real-time by calling rt_thread_init and later rt_task_delete.

Now here's the problem:

If the calling thread of my function IS already real-time, then I am rt_thread_initing which I assume simply fails, but then I rt_task_delete and make that thread non-real-time (besides the fact that when the thread itself (assuming I changed nothing) again rt_task_deletes, RTAI crashes.

If the calling thread of my function IS not real-time, everything is ok.

For now, I resorted to taking a parameter in the function so that the calling function tells the library if it is real-time or not. However, I wanted to know if RTAI has a function or something so I could use to automatically detect whether the current thread is real-time or not.

Don't know if there are any RTAI users here (I certainly didn't see the RTAI tag), but hope there would be.

Shahbaz
  • 46,337
  • 19
  • 116
  • 182

1 Answers1

1

Never tried it myself, so this is a guess - but did you consider using rt_whoami?

Get the task pointer of the current task.

https://www.rtai.org/documentation/magma/html/api/api_8c.html#a12

I would imagine it will fail (return NULL?) if you are in a non RT task...

gby
  • 14,900
  • 40
  • 57
  • It was really a desperate act to ask this in stack overflow, but I'm glad I did! Take this +1 for now until Monday that I go try it – Shahbaz Oct 15 '11 at 22:11
  • You know, turns out `rt_whoami` is only in kernel space and `rt_buddy`, according to the maintainer of RTAI is the replacement, although he said it's only good for debugging. However, the email I read this from was from 2003 and `rt_buddy` is not in the documentations either. I have asked to see whether this is still true. – Shahbaz Oct 17 '11 at 15:46