Re: Model / Threading Advice
Quote:
Originally Posted by
tntcoda
The way i want to do it is by passing a pointer to the model to each thread, then make simple function calls to the model via the pointer, and make sure everything is properly locked with mutex's.
Bad idea - slow and probably won't work anyway as you can't protect the internal implementation of the model.
Quote:
The second approach i have been advised of is to use signals/slots for cross thread communication, im not really sure how this would work for 2 way communication. I can understand i could send a signal from the worker thread to the model and do something, but i would need to get data back as well?
Send another signal back to the calling object.
Quote:
Maybe i could pass a pointer to something as a parameter in the signal to be utilized from the model?
Passing pointers across threads is a bad idea in general.
Quote:
Are signals/slots thread safe by default?
Yes.
Quote:
I would really appreciate some advice on how i should design this, its phraphs not ideal having worker threads interact directly with a model but I think i will have to, i just need a simple/safe way to do it.
It depends what do you need those threads for.
Re: Model / Threading Advice
Quote:
Originally Posted by
wysota
Bad idea - slow and probably won't work anyway as you can't protect the internal implementation of the model.
Send another signal back to the calling object.
Passing pointers across threads is a bad idea in general.
Yes.
It depends what do you need those threads for.
Thanks alot, the threads are basically are going to be performing operations with a QSslSocket based around the data that is retrieved from the model.
So am i right in thinking i would send a signal from the thread to the model, process it at a slot in the model and send a signal back to the worker, with some data in its parameters?
Re: Model / Threading Advice
Quote:
Originally Posted by
tntcoda
Thanks alot, the threads are basically are going to be performing operations with a QSslSocket based around the data that is retrieved from the model.
Ok, but why threads? Why not do it all in a single thread? Do you have 20 processing units in your machine that you want to use 20 threads?
Quote:
So am i right in thinking i would send a signal from the thread to the model, process it at a slot in the model and send a signal back to the worker, with some data in its parameters?
Yes, this is possible.
Re: Model / Threading Advice
Im using threads because i want to have up to 10 sockets downloading (synchronous io) simultaneously, is there a better approach than using threads for this purpose?
Re: Model / Threading Advice
You can do that in a single thread. Qt doesn't use synchronous sockets, so you'll be using asynchronous downloading anyway. If you're not doing any heavy processing with the downloaded data, one thread will be sufficient.
Re: Model / Threading Advice
Hi,
Finally? Did we go for threads? How did it work out?