Hi all,

I've been looking for a similar question but I haven't found any (maybe because this is not possible).

I am building an application that would simulate different entities executing concurrently (vehicles, people, etc). I would like each of them to have its own thread and to execute paralelly. Although being quite a big amount of elements (imagine 10000) most of the time their threads would be sleeping. I don't know if tackling this problem with QThreads is not the right way but currently I have tried different implementations:


  1. Creating all entities as QRunnable and running them all paralelly at the same time:
    I get a "Cannot create pipe main loop wake-up: too many files open" error, for running too many threads.

  2. Creating all entities as QRunnable and calling the QThreadPool to run them :
    The threadpool executes the number of threads defined by QThreadPool::globalInstance()->setMaxThreadCount() (let's say 28) and queues the rest. But even if the QRunnable attached to one of this 28 threads is sleeping, the thread wont be released and used by another queued entity (so in the end only 28 entities would be executed).

  3. I've been trying today QtConcurrent::run() but for what I've tried it seems to work in the same way QThreadPool does


Is there any way to implement this? If QThreadPool would detach sleeping threads and run the queued awaiting ones all my problems would be fixed. Or am I approaching the problem completely wrong?

Thanks in advance for your time.