Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » How SQL deal with multiple threads?
How SQL deal with multiple threads? [message #48497] Mon, 10 July 2017 11:18 Go to next message
akebee is currently offline  akebee
Messages: 90
Registered: August 2011
Location: China
Member
The tutorial "Skylark09" shows "session per-thread" mode to deal with multiple threads,
database session connected when starting each thread。

So, eath thread each sql session, but the SQL is a global main database, i think is a global session, how it deal with multiple threads? Embarassed

[Updated on: Mon, 10 July 2017 11:21]

Report message to a moderator

Re: How SQL deal with multiple threads? [message #48498 is a reply to message #48497] Mon, 10 July 2017 11:28 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
replying just from memory, without checking anything, so I may be wrong...

IIRC "SQL" is macro hiding the default SqlSession instance, so it's probably not supposed to be used in multi-thread source, you should use the underlaying SqlSession instances themselves. But if that example is doing it, then it's probably ok, and the SQL definition accounts for it? But I don't think so.

Here's the docs about SqlSession for further reading (I'm not going to, sorry Smile):
http://www.ultimatepp.org/src$Sql$SqlSession$en-us.html
Re: How SQL deal with multiple threads? [message #48499 is a reply to message #48497] Mon, 10 July 2017 11:59 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Check docs for void SqlSession::PerThread(bool b = true)

means you can choose:

- either you have single global SQL object (and need to serialize access to it)
- or each thread has its own one (but of course, then each thread needs to create and open its DB connection)
Re: How SQL deal with multiple threads? [message #48500 is a reply to message #48498] Mon, 10 July 2017 12:00 Go to previous messageGo to next message
akebee is currently offline  akebee
Messages: 90
Registered: August 2011
Location: China
Member
if the SQL not support multi-thread the SqlExp would be have no use in multi-thread? Confused
Re: How SQL deal with multiple threads? [message #48501 is a reply to message #48499] Mon, 10 July 2017 12:26 Go to previous messageGo to next message
akebee is currently offline  akebee
Messages: 90
Registered: August 2011
Location: China
Member
yeah, i understand a little
the SqlSession::PerThread set sPerThread
thread__ SqlSession *sThreadSession;
...
	#ifdef _MULTITHREADED
		if(sPerThread)
			sThreadSession = &s;
		else
	#endif
			sGlobalSession = &s;
		return;

i don`t see how each thread has a sThreadSession ?
Re: How SQL deal with multiple threads? [message #48502 is a reply to message #48500] Mon, 10 July 2017 12:28 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
akebee wrote on Mon, 10 July 2017 12:00
if the SQL not support multi-thread


I am not sure where you got that idea...

Sql fully supports MT.

Only thing for you to decide is whether 'default' SQL session is really 'global' (single one in the process), or you have an option to have SQL per-thread. By SQL in this paragraph I mean 'SQL default session object'.

Note that even if you opt for single global SQL, multithreading is still a go. You can either open other session in thread, or you can even use that single global SQL, but need to mutex it.

Re: How SQL deal with multiple threads? [message #48503 is a reply to message #48501] Mon, 10 July 2017 12:30 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
akebee wrote on Mon, 10 July 2017 12:26
yeah, i understand a little
the SqlSession::PerThread set sPerThread
thread__ SqlSession *sThreadSession;
...
	#ifdef _MULTITHREADED
		if(sPerThread)
			sThreadSession = &s;
		else
	#endif
			sGlobalSession = &s;
		return;

i don`t see how each thread has a sThreadSession ?


Because 'thread__' ?
Re: How SQL deal with multiple threads? [message #48504 is a reply to message #48503] Mon, 10 July 2017 13:26 Go to previous message
akebee is currently offline  akebee
Messages: 90
Registered: August 2011
Location: China
Member
oh yes, it is!!
#ifdef DEPRECATED
#define thread__ thread_local
#endif


[Updated on: Mon, 10 July 2017 13:30]

Report message to a moderator

Previous Topic: Oracle 12c
Next Topic: ODBC crash
Goto Forum:
  


Current Time: Fri Mar 29 13:23:39 CET 2024

Total time taken to generate the page: 0.02631 seconds