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 » Basic MT queries
Basic MT queries [message #28865] Mon, 20 September 2010 17:16 Go to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Hi,

I am attaching a simple snippet with a thread that performs a dummy loop. I have some very basic queries:

1.- how to stop/start the thread by using the buttons? I guess that ShutdownThreads function is the right one to raise a flag but although the loop stops, the application remains stuck.

2.- I have seen some global functions that are available, such is GuiLock_; is there any information about such a function and other related functions?. What is it for?

Many thanks.

Cheers,

Javier
Re: Basic MT queries [message #28870 is a reply to message #28865] Tue, 21 September 2010 06:50 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Javier

Try the samples Reference/Guilock and GuiMT.

They work very well and are simple.


Best regards
IƱaki
Re: Basic MT queries [message #28872 is a reply to message #28870] Tue, 21 September 2010 12:26 Go to previous messageGo to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Ok. I have checked them and are fine.

Allow me to ask some questions:

1.- Atomic and associated functions, are they similar to INTERLOCKED?

2.- ShutDownThreads function: what is it for? How a thread can be paused and resumed?

3.- Apparently there are numerous global functions in U++ not documented. One of them is GuiLock__? What is this for?.

Cheers.

Thank you,

Javier
Re: Basic MT queries [message #28873 is a reply to message #28872] Tue, 21 September 2010 13:36 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Javier
281264 wrote on Tue, 21 September 2010 12:26

1.- Atomic and associated functions, are they similar to INTERLOCKED?

If I'm not mistaken, Atomic*() functions use platform specific routines for atomic access to variables. INTERLOCKED macro gives you similar effect on entire block. The main difference is that INTERLOCK uses mutex to achieve this, so it is much slower.

281264 wrote on Tue, 21 September 2010 12:26

2.- ShutDownThreads function: what is it for? How a thread can be paused and resumed?

Calling Thread::ShutDownThreads() sets an internal flag that can be checked using Thread::IsShutDownThreads(). If I remember correctly, ShutDownThreads waits till all the threads end. To stop/resume thread you should use a flag for which you check in the thread. It is a good idea to to mark it volatile, e.g. "volatile bool running;".

281264 wrote on Tue, 21 September 2010 12:26

3.- Apparently there are numerous global functions in U++ not documented. One of them is GuiLock__? What is this for?.

GuiLock is one of the ways how to safely update GUI from threads. BTW: There is actually a space, the "__" is used just as a variable name Wink The idea behind GUILock is that as long as the object __ (or gl) exists, the main thread is blocked from changing GUI, so it prevents dead-locks. The lock is actually acquired in constructor and released in destructor, so it can be easily limited using brackets.

Honza

PS: Looking at you sources from first post, I noticed that you use the thread1 variable to call the static functions (which can be called without an object). Actually the whole code in this case could be done without using the variable at all. To start thread in such case you can use Thread::Start(callback). The only downside is that you can't Wait() for such thread, but in many cases that is not necessary.
Re: Basic MT queries [message #28874 is a reply to message #28873] Tue, 21 September 2010 18:03 Go to previous messageGo to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Honza:

Many thanks. Fine explanation. What is Wait() function for?

Javier
Re: Basic MT queries [message #28875 is a reply to message #28874] Tue, 21 September 2010 18:46 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

281264 wrote on Tue, 21 September 2010 18:03

Honza:

Many thanks. Fine explanation. What is Wait() function for?

Javier

Wait() is for situations where you need to block the program until a given thread finishes (e.g. because you need it's result before your program can continue).

Example:
Thread t1,t2;
//start threads to do some work in parallel
t1.Run(fn1); // do first half of work
t2.Run(fn2); // do second half of work
// wait till both finish so you can process results
t1.Wait();
t2.Wait();
// now you can continue work that needs both threads to be finished ...

Notice that it doesn't matter in which order the threads finish. If you call Wait() on thread that has already finished, it should return immediately.
Re: Basic MT queries [message #28876 is a reply to message #28875] Tue, 21 September 2010 18:53 Go to previous message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Cristal clear.

Many thanks,

Javier
Previous Topic: smtp problem
Next Topic: GLCtrl and multithreading
Goto Forum:
  


Current Time: Thu Mar 28 22:01:17 CET 2024

Total time taken to generate the page: 0.00880 seconds