Ambient cooperative cancellation with green threads
AssigneeMicrosoft Technology Licensing, LLC
InventorsStephen Harris Toub, David Charles Wrighton
Life of this patent
Estimating the term…
Abstract
A device may queue a thread for execution by a thread pool, including configuring an ambient context with a cancellation token. Based on a call of a synchronous method by the thread, the device may determine that the thread uses a green threads model and identify the cancellation token from the ambient context. Based on the thread using the green threads model, the device may call an asynchronous method that uses an asynchronous operation to perform a task of the synchronous method, including passing the asynchronous method the cancellation token. Based on identifying a state change of the cancellation token, the device may terminate the asynchronous operation.
Claims20
A method implemented in a computer system that includes a processor system comprising:
- queuing a first thread for execution by a thread pool, including configuring a first ambient context of the first thread with a cancellation token;
- based on a first call of a first synchronous method by the first thread,
- determining that the first thread uses a green threads model;
- and
- identifying the cancellation token from the first ambient context;
- based on the first thread using the green threads model, calling an asynchronous method that uses an asynchronous operation to perform a first task of the first synchronous method, including passing the asynchronous method the cancellation token;
- based on identifying a state change of the cancellation token, terminating the asynchronous operation;
- queuing a second thread for execution by the thread pool, the second thread having a second ambient context;
- based on a second call of a second synchronous method by the second thread, determining that the second thread does not use the green threads model;
- and
- based on the second thread not using the green threads model, performing a second task of the second synchronous method.
A computer system comprising:
- a processor system;
- and
- a computer storage medium that stores computer-executable instructions that are executable by the processor system to at least:
- create a first thread for execution by a thread pool, including configuring a first ambient context of the first thread with a cancellation token;
- based on a first call of a first synchronous method by the first thread:
- determine that the first thread uses a green threads model;
- and
- identify the cancellation token from the first ambient context;
- based on the first thread using the green threads model, call an asynchronous method that uses an asynchronous operation to perform a first task of the first synchronous method, including passing the asynchronous method the cancellation token;
- based on identifying a state change of the cancellation token, terminate the asynchronous operation;
- create a second thread for execution by the thread pool, the second thread having a second ambient context;
- based on a second call of a second synchronous method by the second thread, determine that the second thread does not use the green threads model;
- and
- based on the second thread not using the green threads model, perform a second task of the second synchronous method.
A computer-readable storage medium that stores computer-executable instructions that are executable by a processor system to at least:
- create a first thread for execution by a thread pool, including configuring a first ambient context of the first thread with a cancellation token;
- based on a first call of a first synchronous method by the first thread:
- determine that the first thread uses a green threads model;
- and
- identify the cancellation token from the first ambient context;
- based on the first thread using the green threads model, call an asynchronous method that uses an asynchronous operation to perform a first task of the first synchronous method, including passing the asynchronous method the cancellation token;
- based on identifying a state change of the cancellation token, terminate the asynchronous operation;
- create a second thread for execution by the thread pool, the second thread having a second ambient context;
- based on a second call of a second synchronous method by the second thread, determine that the second thread does not use the green threads model;
- and
- based on the second thread not using the green threads model, perform a second task of the second synchronous method.
Dependencies are inferred from the claim text.