Svisstack
Svisstack

Reputation: 16616

How to implement waitAny on more than 64 handles?

How to implement waitAny on more than 64 handles?

I have simple problem, i have many threads working until end of data, when thread is end of data then signalling to thread on what i running this waitAny for idle thread and give him next package of data.

Upvotes: 4

Views: 1069

Answers (3)

Michael Burr
Michael Burr

Reputation: 340208

You might want to consider implementing something like a queue for notification packets for the 'waitAny' thread to wait on. When one of your multitude of threads completes it's operation, it places a notification packet on the queue. Your waitAny turns into a wait on a single event that indicates something is in the queue.

Upvotes: 5

Roman Ryltsov
Roman Ryltsov

Reputation: 69662

Effective wait is limited by API MAXIMUM_WAIT_OBJECTS which is 64. Apart from having your app redesigned to use fewer handles, you can either switch to poll mode (wait for each 64 separately with timeout of zero, and wait for small non-zero amount if all handles are not signaled), or split objects and waits between multiple threads of execution.

You might also want to revisit earlier discussions, e.g.

Upvotes: 1

Oleg Dok
Oleg Dok

Reputation: 21766

Implement cascading waits with additional threads to wait for pack of WaitHandles and signaling the other up on hierarchy.

Or test them in bulks without actual waits (without timeout set)

Upvotes: 3

Related Questions