Home » U++ Library support » U++ MT-multithreading and servers » How to use Thread()
Re: How to use Thread() [message #44018 is a reply to message #44016] |
Sat, 13 December 2014 00:02   |
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.
|
|
|
Goto Forum:
Current Time: Mon Jul 07 20:10:21 CEST 2025
Total time taken to generate the page: 0.04163 seconds
|