Page 1 of 1

LOFi list thread safe needed

Posted: Mon Dec 04, 2023 1:37 pm
by Rings
For a project I need, among other things, a thread-safe variant of a
LOFI list.
So get the last element out and add the newest element at the end of the
list.

The whole thing must be thread-safe because I fill the list from one thread
and remove the oldest element (last) from another for editing.

Even more detailed:
Data packets arrive via the serial interface which I want to push into a list.
I want to process these data packets at another location.
The data packets are only about 20 bytes wide, so they may fit into an array.
Or just in a memory area, which I would have to create when adding an element
and delete it when removing the element.

I haven't found the right thing here in the forum yet.
A post from the user "IDLE" does not work either.

I also had a look at the normal linked list, but it doesn't seem to work that easily.

I look forward to great suggestions .

Before I forget, please don't use an API, must be multiplatform.

Re: LOFi list thread safe needed

Posted: Mon Dec 04, 2023 7:33 pm
by idle
I fixed it
https://www.purebasic.fr/english/viewto ... fo#p377516

but maybe you could use this lock free ring buffer, much faster than using a mutex, and to think they even named it after you. :wink:
https://www.purebasic.fr/english/viewtopic.php?t=79172

Re: LOFi list thread safe needed

Posted: Mon Dec 11, 2023 6:14 pm
by Rings
thx @idle, i'm on it now.
i will post some stuff later

Re: LOFi list thread safe needed

Posted: Tue Dec 12, 2023 2:33 pm
by Olli
Maybe my bad... I do not know "LOFI"

I know "FIFO" (the first input, is the first output). Queue concept.

And I know "LIFO" (the last input, is the first output). Stack concept.

What about "LOFI" ? Is it FIFO, or LIFO ?

Re: LOFi list thread safe needed

Posted: Tue Dec 12, 2023 2:58 pm
by Mindphazer
Last Out, First In
"Dernier sorti, premier rentré"
Le dernier élève sorti de la salle de Philo entrera en premier dans la salle de Maths

Re: LOFi list thread safe needed

Posted: Tue Dec 12, 2023 7:48 pm
by Olli
Okay, LOFI => LIFO

Just the "outdoor" and the "indoor" are swapped, LOFI is so a stack concept.