PDA

View Full Version : QThreadPool search threads



Cerberus
7th September 2015, 19:25
I have a main application that needs to handle multiple threads. I have stored the different threads in a QThreadPool which then handles the execution. But I need to access specific threads from this pool either from the main application that contains the QThreadPool (which might be easier to accomplish) or from the single threads directly.

Is it possible to access a specific thread when using QTreadPool or do I have to use something else instead?

anda_skoa
7th September 2015, 20:07
The usual purpose of a thread pool is to make handling of individual threads unnecessary.

What exactly are you trying to do that instantes this requirement?

Cheers,
_

Cerberus
7th September 2015, 20:13
I have a server that accepts different clients. Every client is handled in a different thread. The clients should be able to send messages between them, therefore they need to be able to access a specific thread

anda_skoa
7th September 2015, 21:50
Aside from the obvious question of why you need separate threads to handle client connections, why does one client handler need to know about another client handler's thread?

Cheers,
_

Cerberus
8th September 2015, 10:19
As I mentioned above it is one of the solutions I came up, but I am open for suggestions if there is a better way to do it.
Nevertheless I will have to access a specific thread/Client from the server then to be able to forward the received message from one client, or not??
How else would I send the messages between the clients?

anda_skoa
8th September 2015, 10:50
As I mentioned above it is one of the solutions I came up, but I am open for suggestions if there is a better way to do it.

Unless you expect complex and CPU intensive tasks on each client handler, you could simply handle them with the same thread.



Nevertheless I will have to access a specific thread/Client from the server then to be able to forward the received message from one client, or not??

You write "thread/Client" but those two things are not the same.
So far you have only provided indication that you need to access client handlers, but there is nothing suggesting you need access to a client handler's thread.



How else would I send the messages between the clients?

Same as in a single threaded application:
- method call
- signal/slot connection
- sending an event

None of which require access to any specific thread.

Cheers,
_