[riot-devel] sched_active_thread is a volatile pointer, but volatile is ignored

Juan Ignacio Carrano j.carrano at fu-berlin.de
Mon Jan 7 11:21:54 CET 2019


Hi Kees,

On 1/4/19 10:18 PM, Kees Bakker wrote:
> 
> In a lot of our code sched_active_thread is converted into
> a non-volatile pointer. Is that correct? Here [1] it is described
> that such conversion is undefined behavior.

My understanding is that `sched_active_thread` is volatile in a thread 
context, but not in the kernel context. Therefore I thought that 
discarding the qualifier in code that runs in the scheduler should be 
OK, although a bit dirty. Now, if you tell me it's undefined behavior 
then it is NOT OK.

I had thought of two ways to fix this:

* Linker-level aliasing: define `sched_active_thread` once (in the 
scheduler, as non volatile) and declare it as `extern volatile` in those 
headers that are seen by user applications, and as `extern` in headers 
seen by the kernel.

* C-level aliasing: redefine sched_active_thread as a union of a 
volatile and non-volatile.

AFAICT neither of those ways of accessing should result in undefined 
behavior, as there as no casts being performed. What do you think?

Regards,

Juan.


More information about the devel mailing list