What kind of safety provides this compiler option?
If for example a thread is iterating a list or accesing an allocated memory area can another thread acces that list or memory?, or are mutex, semaphores still need it?
What does Threadsafe do?
Re: What does Threadsafe do?
The default libraries aren't thread aware and functions may cause crashes or problems in threaded programs. They may be slightly faster than the threaded ones because they don't need to set up and manage synchronisation devices, and don't need to wait etc. If you are writing a single threaded program it makes sense to take advantage of this, so that's why it's an option.
This option tells the compiler to replace the single threaded functions with versions which do use synchronisation devices internally and so won't crash a threaded program or cause a synchronisation fault.
Your code must still provide the necessary synchronisation on its own activities to ensure that it doesn't cause synchronisation problems though. So yes, you will still need mutexes and semaphores where appropriate.
This option tells the compiler to replace the single threaded functions with versions which do use synchronisation devices internally and so won't crash a threaded program or cause a synchronisation fault.
Your code must still provide the necessary synchronisation on its own activities to ensure that it doesn't cause synchronisation problems though. So yes, you will still need mutexes and semaphores where appropriate.
Last edited by spikey on Mon Sep 30, 2024 5:32 pm, edited 2 times in total.
Re: What does Threadsafe do?
It would be good to know if this actually applies to the underlying libs.
For example, does the sqlite3 lib get compiled with different threadsafe settings?
That would speed up database operations if the app was truly single threaded.
For example, does the sqlite3 lib get compiled with different threadsafe settings?
That would speed up database operations if the app was truly single threaded.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: What does Threadsafe do?
Apparently not. I guess I should have qualified my remark and said PB libraries.skywalk wrote: Mon Sep 30, 2024 3:01 pm Does the sqlite3 lib get compiled with different threadsafe settings?
Code: Select all
PRAGMA compile_options;
...
THREADSAFE=1
Re: What does Threadsafe do?
It mostly affect the string operations, and a lot of PB libs which requires threaded version (2DDrawing, HTTP etc.)
Re: What does Threadsafe do?
This could get a bit more attention in the documentation.
I still don't know if a list or map is 100% threadsafe and just treat them as if they're not.
I still don't know if a list or map is 100% threadsafe and just treat them as if they're not.
Re: What does Threadsafe do?
Hi, thanks for the responses so i assume locking mechanisms are still needed.
Re: What does Threadsafe do?
List and map are not threaded
Re: What does Threadsafe do?
But they could, at least for pure concurrent read access.
Re: What does Threadsafe do?
Yup, I got burned by this early on. The current element was tricky with threads.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum