Opened 10 years ago

Last modified 10 years ago

#11227 confirmed enhancement

wxThreadPool class for multi-threaded job management

Reported by: net147 Owned by:
Priority: low Milestone:
Component: base Version: stable-latest
Keywords: Cc:
Blocked By: Blocking:
Patch: no

Description

I think it would be useful if wxWidgets has some sort of wxThreadPool class.

Some things that this class might implement:

  • Default constructor - create thread pool with max threads set to CPU count
  • Overloaded constructor that takes a max thread count
  • Get/set max thread count
  • Add a job to the pool, returns true if job started immediately or false if all threads currently busy
  • Wait for jobs all in pool to finish
  • Cancel remaining jobs in pool and wait for currently running jobs to finish

Change History (1)

comment:1 Changed 10 years ago by vadz

  • Status changed from new to confirmed

I agree that a thread pool class would be useful, any contributions would be welcome (although it would be nice to discuss the API first).

FWIW I have such class in non-wx code and even in a very simple form it's already quite useful:

class ThreadManager
{
public:
  ThreadManager(unsigned maxThreads = 0);
  ~ThreadManager() { WaitForWorkerThreads(); }

  void QueueTask(const boost::function<void()>& task);

protected:
  /**
      Wait until all worker threads terminate.

      Called from our dtor but may also be called from the derived classes to
      ensure that the cleanup is done when no threads are running any more.
   */
  void WaitForWorkerThreads();

private:
  ...
};
Note: See TracTickets for help on using tickets.