Preferences do not work with threads

Just starting out? Need help? Post your questions and find answers here.
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Preferences do not work with threads

Post by uwekel »

Hi,

from this post http://www.purebasic.fr/english/viewtop ... 13&t=48459 i have learned that the preferences library is intend to work with threads, too. But not so with Linux. Here is a sample code:

Code: Select all

Procedure Work(*Args)
  Debug ReadPreferenceInteger("Test", 0)
EndProcedure

OpenPreferences(GetHomeDirectory() +"test.conf")
WritePreferenceInteger("Test", 1)
Debug ReadPreferenceInteger("Test", 0)
Thread = CreateThread(@Work(), 0)
WaitThread(Thread)
ClosePreferences()
Dont forget the Thread-Safe option before running the code.

Regards
Uwe
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Preferences do not work with threads

Post by freak »

You have to write in the same thread where you open the preferences. Each thread has its own separate preferences state.

You can have two threads working on separate preferences files in parallel, you can't have two threads working on the same one. Its not a bug.
quidquid Latine dictum sit altum videtur
Post Reply