mr49
mr49

Reputation: 1063

Is there an equivalence of NSOperationQueue on Windows?

On OSX or iOS, NSOperationQueue is very useful for dispatching asynchronous tasks. Is there similar facility on Windows?

Upvotes: 1

Views: 301

Answers (2)

Jerry Coffin
Jerry Coffin

Reputation: 490728

Windows has a couple of Thread Pool APIs. The "old thread pool API" is more like NSOperationQueue, but the New Thread Pool API is recommended for new code.

Upvotes: 2

Adam Maras
Adam Maras

Reputation: 26883

The most similar API for Win32 is the Thread Pool API.

From MSDN:

The thread pool application programming interface (API) uses an object-based design. Each of the following objects is represented by a user-mode data structure:

  • A pool object is a set of worker threads that can be used to perform work. Each process can create multiple isolated pools with different characteristics as necessary. There is also a default pool for each process.

  • A clean-up group is associated with a set of callback-generating objects. Functions exists to wait on and release all objects that are members of each clean-up group. This frees the application from keeping track of all the objects it has created. A work object is assigned to a pool and optionally to a clean-up group. It can be posted, causing a worker thread from the pool to execute its callback.

  • A work object can have multiple posts outstanding; each generates a callback. The post operation cannot fail due to lack of resources.

  • A timer object controls the scheduling of callbacks. Each time a timer expires, its callback is posted to its worker pool. Setting a timer cannot fail due to lack of resources.

  • A wait object causes a waiter thread to wait on a waitable handle. After the wait is satisfied or the time-out period expires, the waiter thread posts the wait objects' callback to the wait's worker pool. Setting a wait cannot fail due to lack of resources.

  • An I/O object associates a file handle with the I/O completion port for the thread pool. When an asynchronous I/O operation completes, a worker thread picks up the status of the operation and calls the I/O object's callback.

Upvotes: 0

Related Questions