Realtime thread from Photon

I intend to write a thread spawned from a Photon callback function to control hardware in ‘realtime’.

I need to boost the priority level of the thread preferably in the callback function itself, before the call to the thread create function.

Does anyone have any ideas about this?


Look at sched_setparam() but that’s after the thread is started obviously. You can specify the thread priority when you create with pthread_create. But you can’t boost the priority of the thread in the callback before the call to thread create because the thread doesn’t exists yet ;-)

In general mixing GUI and realtime in the same program is not a good practice even though you are using threads. If the GUI is stop or crashes so does the control thread and vise versa. If you need to upgrade the GUI you need to stop the control thread as well. While if they are separate programs you can restart one without affecting the other.

Also Photon is not thread safe, so your control thread can’t use Photon library call. It’s possible by using PtEnter and PtLeave but it can get messy real fast ;-)

A busmastering video card will take a lot of the realtime out of your system. Since this is literally a hardware issue, if you really need determinism, I would not run a GUI on the same machine.

Thanks for the replies. From Mario’s suggestions I think i can setup the priority in a sched_param struct before calling pthread_create. The documentation is not too clear on this - and i am new to posix/qnx so can be a bit confusing
My idea was:

pthread_attr_t attr;
sched_param * param;
pthread_attr_init( &attr );
pthread_attr_getschedparam( &attr, param );
*param->sched_priority = 50;
pthread_attr_setschedparam( &attr, );
pthread_create( NULL, &attr, &function, NULL );
?? :confused:

I still need to test this.

There are no photon library calls in the control software so i am not too worried about that problem

Is it best not to start photon at all? I am not sure where to find the options to change this as the setup boots into the GUI automatically. can i get round the associated problems by running multi-threaded programs from a ‘command terminal’. I assume that they will still go down if the GUI crashes.

I am using an old S3 pci card, i asume that this is busmastering?

sorry for all these basic questions! :blush:

error - message posted twice.

Automatically boot into photon? Try “touch /etc/system/config/nophoton” and reboot

If a program crashes it won’t affect other programs (aside from dependecies in your design). If a thread crash the program it belong too with die along with its thread.

If you start a program that isnt’ using Photon, you can stop/restart/kill/beat/trash/crash Photon and it won’t affect your program and vice versa.