memory management by "active" flag
in many places, authors use static memory allocation in globally accessed arrays,
to grab/free buffers, they do like (in best case):
Thread 1:
1 for (int i=0; i<arrayEnd; i++) {
2 if (array[i].active == false) {
3 array[i].active = true;
4 ....
5 }
Thread 2:
11 for (int i=0; i<arrayEnd; i++) {
12 if (array[i].active == true) {
13 ....
14 array[i].active = false;
15 }
even this is not thread safe:
2 if (array[i].active == false) {
3 array[i].active = true;
is not atomic
very often, it is even much more dirty, like
find_nr_ulsch(), find_nr_dlsch() : how do I know this function is never called from two threads ?
they are very dangerous: it returns a 'free index', that is filled later by nr_fill_ulsch() instead of allocating a slot inside find_nr_ulsch()
Complex tests like:
if ((ulsch_harq->status == NR_ACTIVE) &&
(ulsch_harq->frame == frame_rx) &&
(ulsch_harq->slot == slot_rx) &&
(ulsch_harq->handled == 0)
are far from being atomic