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++ Core » multithread access to the same control
multithread access to the same control [message #759] Tue, 31 January 2006 08:42 Go to next message
hojtsy is currently offline  hojtsy
Messages: 241
Registered: January 2006
Location: Budapest, Hungary
Experienced Member
I am writing a software which downloads and parses 4 XML files in paralel from different HTTP servers. When each thread finishes the parsing it should update a field in an ArrayCtrl. I don't find any docs about multithreading in u++. Does the HttpClient support paralel downloads of diffetent files in different threads? Is it OK to access the ArrayCtrl from multiple threads? Do I need mutex for it? Is the multithreading support available under Unix?
Re: multithread access to the same control [message #763 is a reply to message #759] Tue, 31 January 2006 15:35 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, multithreading model is quite simple:

GUI must runs in single thread and is not serialized.

What IS serialized (locked) is "timer" queue (" because it is in fact used for many other things as well). Means you can safely post callbacks to GUI thread.

Also, Core types ARE serialized.

So the right thing to do is to run HttpClient in different threads (I hope Tom will protest here if there is any problem with it, but I do not thing so) and update your ArrayCtrl using PostCallback.

Multithreading support is available in Unix (but is tested even less than the one on Win32... in fact I doubt that any U++ app ever run on real multiprocessor machine, and until then, some problems might be left unrevealed).

Mirek
Re: multithread access to the same control [message #767 is a reply to message #763] Wed, 01 February 2006 00:11 Go to previous messageGo to next message
hojtsy is currently offline  hojtsy
Messages: 241
Registered: January 2006
Location: Budapest, Hungary
Experienced Member
I have a question about the Thread object.
Suppose that every time a button is pressed, I would like to start a new worker thread which terminates after a processing task is finished by it.
void onButton()
{
  Thread t;
  t.Run( THISBACK(ProcessingFunction) );
}
Will the destructor of the Thread object terminate the thread? If yes, then I need dynamic allocation of Thread, but I won't know when to release that memory.
Re: multithread access to the same control [message #768 is a reply to message #767] Wed, 01 February 2006 00:18 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
No, thread must terminate itself. Terminating via Thread variable is not possible.
Re: multithread access to the same control [message #777 is a reply to message #768] Wed, 01 February 2006 22:59 Go to previous messageGo to next message
hojtsy is currently offline  hojtsy
Messages: 241
Registered: January 2006
Location: Budapest, Hungary
Experienced Member
I created a small example multithreaded application. You can add numbers to a list, triggering a new thread which counts the number of divisors, and updates the table when it is finished. Even though a slow implementation was choosen you still need to use large numbers to be able see the multithreading in action. The example uses Thread and PostCallback. As no example is present for these features, maybe my application, or a modified version could be added to the examples or reference directory.
  • Attachment: Divisors.zip
    (Size: 1.28KB, Downloaded 1486 times)
Re: multithread access to the same control [message #799 is a reply to message #777] Thu, 02 February 2006 23:31 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
A very good idea.

I have spent all the evening working on it Smile

There were two problems with original example:

* I think that it is quite error-prone to run several threads in single instance. Chances that you make unserialized access to some member variable are high

* However, the more serious problem is with application exit. When you press Close button, chances are that thread will be running and will invoke dangling callback.

I have tried to fix both and to improve the example (using uint64 etc...) - it is now in "reference".

Mirek
  • Attachment: GuiMT.zip
    (Size: 1.44KB, Downloaded 1631 times)
Previous Topic: regex (assembly) from boost
Next Topic: storing my struct in a Value
Goto Forum:
  


Current Time: Thu Apr 25 21:02:22 CEST 2024

Total time taken to generate the page: 0.02804 seconds