This project refers to an Arduino library implementing a generic, dynamic queue (array version).
The data structure is implemented as a class in C++.
For more information, you can get the project itself ‘QueueArray‘.
This project refers to an Arduino library implementing a generic, dynamic queue (array version).
The data structure is implemented as a class in C++.
For more information, you can get the project itself ‘QueueArray‘.
It seems that the queue you are using in your Arduino application is a common in-memory resource. Since multiple code segments use it either for calling enqueue or dequeue. This behavior can lead to a race condition since the interrupt service routines are executed asynchronously. You could use a locking mechanism to protect the shared resource either by introducing in your code semaphores or mutexes.
A variable should be declared volatile whenever its value can be changed by something beyond the control of the code section in which it appears, such as a concurrently executing thread. In the Arduino, the only place that this is likely to occur is in sections of code associated with interrupts, called an interrupt service routine.
By playing with the library you can find the best place to add it.
Thanks Efstathios for this nice library.
Is it possible to use your library in combination with interrupts?
I would like to enqueue the micros() value when an interrupt occurs and then process the values later in the main code.
I wonder if any variable should be declared as volatile or if I should disable interrupts when I’m dequeuing a value.