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++ MT-multithreading and servers » How to use Thread()
How to use Thread() [message #44016] Fri, 12 December 2014 22:21 Go to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

So far I have never used Threads... and to tell the truth I am rather confused about them.
My GUI app frezee while some operation last 2 or 3 seconds (perform calculation and writing on a sqlite database). This is rather annoying because it seems the app is going to crash.
So I thought to run a Thread for this operation and let the GUI to be free to use for other task. I hope this make sense.

The problem is that the compiler is complaining about Upp::callback, see below, that I do not understand (I used the GUI MT flag).

The function I would like to run in a thread ( SavePairing(num1, num2) ) is a member function of an external class called 'vegadb' and 'DB' is just an instance of vegadb. I tried without success:

Thread().Run( DB.SavePairing(num1, num2) );

Thread().Run( callback2( DB.SavePairing, num1, num2 ) );

Thread().Run( callback2( vegadb::SavePairing, num1, num2 ) );

I tried even callback3. Does anybody have a suggestion?
Thanks,
Luigi

PS: typical error message:

C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C3867: 'vegadb::SavePairing': function call missing argument list; use '&vegadb::S
avePairing' to create a pointer to member
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Gate4<P1,P2,P3,P4> Upp::callback2(const O *,bool (__thiscall M::* )(P
1,P2,P3,P4,Q1,Q2) const,T1,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(572) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Gate4<P1,P2,P3,P4> Upp::callback2(O *,bool (__thiscall M::* )(P1,P2,P
3,P4,Q1,Q2),T1,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(566) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Gate3<P1,P2,P3> Upp::callback2(const O *,bool (__thiscall M::* )(P1,P
2,P3,Q1,Q2) const,T1,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(523) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Gate3<P1,P2,P3> Upp::callback2(O *,bool (__thiscall M::* )(P1,P2,P3,Q
1,Q2),T1,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(517) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Gate2<P1,P2> Upp::callback2(const O *,bool (__thiscall M::* )(P1,P2,Q
1,Q2) const,T1,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(469) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Gate2<P1,P2> Upp::callback2(O *,bool (__thiscall M::* )(P1,P2,Q1,Q2),
T1,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(463) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Gate1<P1> Upp::callback2(const O *,bool (__thiscall M::* )(P1,Q1,Q2)
const,T1,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(415) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Gate1<P1> Upp::callback2(O *,bool (__thiscall M::* )(P1,Q1,Q2),T1,T2)
' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(409) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Gate Upp::callback2(const O *,bool (__thiscall M::* )(Q1,Q2) const,T1
,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(361) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Gate Upp::callback2(O *,bool (__thiscall M::* )(Q1,Q2),T1,T2)' : expe
cts 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(355) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Callback4<P1,P2,P3,P4> Upp::callback2(const O *,void (__thiscall M::*
)(P1,P2,P3,P4,Q1,Q2) const,T1,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(269) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Callback4<P1,P2,P3,P4> Upp::callback2(O *,void (__thiscall M::* )(P1,
P2,P3,P4,Q1,Q2),T1,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(263) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Callback3<P1,P2,P3> Upp::callback2(const O *,void (__thiscall M::* )(
P1,P2,P3,Q1,Q2) const,T1,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(221) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Callback3<P1,P2,P3> Upp::callback2(O *,void (__thiscall M::* )(P1,P2,
P3,Q1,Q2),T1,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(215) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Callback2<P1,P2> Upp::callback2(const O *,void (__thiscall M::* )(P1,
P2,Q1,Q2) const,T1,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(168) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Callback2<P1,P2> Upp::callback2(O *,void (__thiscall M::* )(P1,P2,Q1,
Q2),T1,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(162) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Callback1<P1> Upp::callback2(const O *,void (__thiscall M::* )(P1,Q1,
Q2) const,T1,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(115) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Callback1<P1> Upp::callback2(O *,void (__thiscall M::* )(P1,Q1,Q2),T1
,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(109) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Callback Upp::callback2(const O *,void (__thiscall M::* )(Q1,Q2) cons
t,T1,T2)' : expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(62) : see declaration of 'Upp::callback2'
C:\MyApps\VegaTeam6\SemiManualPairing.cpp(1218) : error C2780: 'Upp::Callback Upp::callback2(O *,void (__thiscall M::* )(Q1,Q2),T1,T2)' :
expects 4 arguments - 3 provided
c:\upp\uppsrc\core\Callback2.h(56) : see declaration of 'Upp::callback2'
Re: How to use Thread() [message #44018 is a reply to message #44016] Sat, 13 December 2014 00:02 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Hi Luigi,

First of all, the syntax.
The callback is constructed using the form:
callbackN(pointerToObject, pointerToObjectRoutine{,N_arguments})
In your case it will be something like
Thread().Run( callback2( &vega, &vegadb::SavePairing, num1, num2 ) );

The second thing is I won't recommend using Thread::Run routine because
1) Each call creates a new thread which is expensive system operation (especially in Windows). So if you call it frequently, you create unnecessary heavy pressure on OS kernel.
2) You can't detect the moment your routine is finished. This is very bad because you should wait for thread and delete it correctly if user wants to quit your app. This is also bad because you must know when some internal variable was changed by parallel routine.

There are different approaches and I recommend designing your inter-threading interactions first. What will be changed? How is main thread is affected on this change? How this data will be safely delivered to calling thread?
If you answer this questions, you may choose the best implementation.
Re: How to use Thread() [message #44019 is a reply to message #44018] Sat, 13 December 2014 15:03 Go to previous message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Hi Pavel,

thanks for the answer.
You are right. I'll think better about it.

Luigi
Previous Topic: Implementing a crash handler
Next Topic: HttpRequest for https page
Goto Forum:
  


Current Time: Tue Apr 16 20:44:35 CEST 2024

Total time taken to generate the page: 0.01130 seconds