Originally Posted by
Lesiok
So if I'm understanding this correctly, I want something like this instead?
void makeASpecificWorkerDoSomething(int indexOfSpecificWorker)
{
// Look up worker
Worker* specificWorker = workersAndThreads[indexOfSpecificWorker].first;
// Schedule worker to do something in its own event loop
QMetaObject::invokeMethod(worker,
SLOT(doSomething
()), Qt
::QueuedConnection);
}
void makeASpecificWorkerDoSomething(int indexOfSpecificWorker)
{
// Look up worker
Worker* specificWorker = workersAndThreads[indexOfSpecificWorker].first;
// Schedule worker to do something in its own event loop
QMetaObject::invokeMethod(worker, SLOT(doSomething()), Qt::QueuedConnection);
}
To copy to clipboard, switch view to plain text mode
Originally Posted by
yeye_olive
Do you really need the workers to run in separate (and persistent) threads, or do you only need them to run outside the main (GUI?) thread, in as many threads as the system can effectively run concurrently? In the latter case, consider using QtConcurrent::run().
I believe I do need them to run in their own persistent threads. Each thread is running a separate copy of a game. Each game uses the event loop on that thread to interface with an AI (or player) either directly (compiled into the program) or through the network. As far as I can tell QtConcurrent just launches a single function per thread and doesn't provide event loops. Is that correct?
I suppose I could re-write the game to use its own manually written loop inside a main function instead of relying on the event loop provided by QThread. Do you believe this would be a better approach?
Bookmarks