LOFi list thread safe needed

Just starting out? Need help? Post your questions and find answers here.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

LOFi list thread safe needed

Post 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.
SPAMINATOR NR.1
User avatar
idle
Always Here
Always Here
Posts: 5915
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: LOFi list thread safe needed

Post 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
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Re: LOFi list thread safe needed

Post by Rings »

thx @idle, i'm on it now.
i will post some stuff later
SPAMINATOR NR.1
Olli
Addict
Addict
Posts: 1242
Joined: Wed May 27, 2020 12:26 pm

Re: LOFi list thread safe needed

Post 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 ?
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 460
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: LOFi list thread safe needed

Post 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
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
Olli
Addict
Addict
Posts: 1242
Joined: Wed May 27, 2020 12:26 pm

Re: LOFi list thread safe needed

Post by Olli »

Okay, LOFI => LIFO

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