Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 226933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:33:24+00:00 2026-05-11T19:33:24+00:00

I want to use a thread pool to both initiate/cancel overlapped read operations —

  • 0

I want to use a thread pool to both initiate/cancel overlapped read operations — using ReadFile() and CancelIo() respectively — as well as handling any completion port events when read operations complete.

  1. Any thread can initiate a read operation
  2. Any thread can handle a read-complete event
  3. Only the thread that initiated a read may cancel it (this is a CancelIo() limitation)

I’m not sure how to implement this. One normally calls GetQueuedCompletionStatus() to wait on completion port events and WaitForSingleObject() to wait on normal events but it’s not clear how to mix the two. If PostQueuedCompletionStatus() would let me specify a specific thread to wake up I’d be set. Any ideas?

UPDATE: The solution must run on Windows XP. Unfortunately this rules out using CancelIoEx() or GetQueuedCompletionStatusEx().

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:33:24+00:00Added an answer on May 11, 2026 at 7:33 pm

    1 and 2 are easy, just use the IO Completion port.

    But, as you have found 3 requires (prior to Windows V61) the same thread.

    If using Windows >= V6, GetQueuedCompletionStatusEx includes an alterable option which will cause it to return is an APC is performed on the thread. So use QueueUserAPC to queue a no-op APC1 when you need that specific thread to do some other work. You will of course need some thread safe queue to provide the interrupted thread with instructions of what to cancel.

    If earlier version compatibility is required then things get more difficult. Possibilities:

    • Use the timeout parameter of GetQueuedCompletionStatus](http://msdn.microsoft.com/library/aa364986) to return regularly to check for cancellations.

    • Or, possibly more practically, divide the thread pool into two groups. Threads that initiate and cancel IO. The rest of the time these threads spend waiting to be signalled to perform one of these actions. The other part of the pool waits on IO completions with GetQueuedCompletionStatus.

    Neither of these is as nice, but that’s always the problem with older versions: they lack functionality.

    1 Use a no-op APC rather than doing work in the APC so the limitations on what can be done in an APC and its inherant issues with concurrency are bypassed. (Since an APC is executed on a thread, any locks that thread hold are held in the APC, any state protected will be arbitrarily inconsistent.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am executing a Callable Object using ExecutorService thread pool. I want to give
I need to use a thread pool in python, and I want to be
I want to use a pool of non-thread-safe encoder instances across multiple concurrent ASP.NET
I use ThreadPoolExecutor to manage a thread pool. What we want are: if the
If we want to use thread specific data in a multithreaded application, how to
Executor seems like a clean abstraction. When would you want to use Thread directly
Whenever I want to modify a winform from another thread, I need to use
I want use this 1 for using Bar code or QR code scanner. I
If I want to read or write a file I could use stream.BeginRead and
I am using ThreadPoolExecutor in my multithreading program, I want each thread should have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.