• Welcome to SQLitening Support Forum.
 

slGetUnusedSetNumber and critical sections / multitasking

Started by Bern Ertl, March 22, 2009, 03:52:41 PM

Previous topic - Next topic

Bern Ertl

I'm building an application that will open a dialog that contains a tab control.  Each tab has child windows/dialogs that will access SQLitening to retrieve data from the same database (at initialization - %WM_INITIALIZE).  I'm planning on using slGetUnusedSetNumber for each child window's callback functions where slSel will be called.  Is it necessary to wrap the slGetUnusedSetNumber + slSel calls inside a critical section to ensure that there are no conflicts with multi-threaded access (ie. tab #1 calls slGetUnusedSetNumber and tab #2 calls slGetUnusedSetNumber before tab #1 can call slSel)?  Or does SQLitening ensure that the Set number returned by slGetUnusedSetNumber is reserved until it's used?

Bern Ertl

I ended up writing the following function:FUNCTION MyslSel( BYVAL sSelect AS STRING) AS LONG

   LOCAL lSetNum AS LONG

   'Begin critical section (gCriticalSection is GLOBAL and initialized in PBMAIN)
   EnterCriticalSection gCriticalSection

   'Call SQLitening
   lSetNum = slGetUnusedSetNumber
   slSel sSelect, lSetNum

   'End critical section
   LeaveCriticalsection gCriticalSection

   'Return set number
   FUNCTION = lSetNum

END FUNCTION

Fred Meier

Bern, sorry I didn't respond sooner, been on a vacation trip.

SQLitening.Dll is not thread-safe so if you have a true multi tasking
situation then it would be necessary to wrap the slGetUnusedSetNumber +
slSel calls inside a critical section to ensure than the set number is
properly used. 

Can't find any reference to a WM_INITIALIZE message -- do you mean WM_INITDIALOG?
I'm not aware that the init messages cause multi tasking concerns.

Bern Ertl

Quote from: Fred Meier on April 09, 2009, 09:55:58 AMSQLitening.Dll is not thread-safe so if you have a true multi tasking
situation then it would be necessary to wrap the slGetUnusedSetNumber +
slSel calls inside a critical section to ensure than the set number is
properly used.

That's what I figured, so I wrote the function posted above. 

Quote from: Fred Meier on April 09, 2009, 09:55:58 AMCan't find any reference to a WM_INITIALIZE message -- do you mean WM_INITDIALOG?
I'm not aware that the init messages cause multi tasking concerns.

Yeah, I meant %WM_INITDIALOG.  There will be four dialogs being initialized at roughly the same time as children of a tab control, hence the multi-tasking concern.

Bern Ertl

Fred, I understand that SQLitening is now thread safe.  I assume though that I still have the same issue with multitasking when calling the two separate functions mentioned above.  Would it be feasible to add a modchar option to slSel to automatically use the next availble set number and return that set number (or to add a new function to effectively combine slGetUnusedSetNumber and slSel and return the set number)?

Fred Meier

Good news, now that SQLitening is thread-safe (each thread has it's own array of set numbers  so all threads can safely use the same set number)  you no longer have to do a slGetUnusedSetNumber which makes it a lot simpler.

QuoteWould it be feasible to add a modchar option to slSel to automatically use the next availble set number and return that set number (or to add a new function to effectively combine slGetUnusedSetNumber and slSel and return the set number)?
Not with the current slSel function, a new function would have to be written.  I don't think there is a need.


Rudolf Fuerstauer

That's a great improvement.
Do you already know when this is available?

Thank you!

F

Bern Ertl

Quote from: Fred Meier on September 18, 2012, 10:10:18 PM... each thread has it's own array of set numbers  so all threads can safely use the same set number ...

Great.  Thanks.  One less headache to worry about.  :)

Fred Meier

QuoteDo you already know when this is available?
SQLitening was made thread-safe starting with version 1.40 released July 2010.