Asynchronous Library Synchronization Context Restoration

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Developers face challenges in ensuring that asynchronous programming interactions with graphical user interface (UI) controls execute on the correct thread, leading to potential bugs due to the need for careful thread management and marshaling.

Innovation Solution

An asynchronous library that remembers the synchronization context of the initial asynchronous method call and restores it before executing the callback, ensuring that the callback executes on the same thread, thereby maintaining thread affinity and simplifying thread management.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Productivity

If asynchronous programming models execute callbacks on an algorithmically or arbitrarily chosen thread from a pool, then thread pool utilization and concurrency are improved, but thread affinity with UI controls is lost leading to bugs

Engineering Contradiction:
ImproveconcurrencyVSAvoidthread affinity
Core Design Contradiction:
ProductivityVSReliability

Solution Approach 1:

The patent introduces a synchronization context as an intermediary that mediates between the thread pool and UI controls. The synchronization context captures the original thread's identity and uses it to route callbacks back to the correct thread, allowing the thread pool to provide concurrency while maintaining UI thread affinity through the mediator's coordination

Inventive Principle:
Principle #24Intermediary (Mediator)

Solution Approach 2:

The patent applies preliminary action by capturing and storing the synchronization context (thread identity) at the time the asynchronous operation is initiated. This pre-captured context is then used later to restore the correct threading environment before executing the callback, ensuring thread affinity without requiring the callback to run on the original thread immediately

Inventive Principle:
Principle #10Preliminary action

2Reliability

If developers manually marshal interactions with UI controls to the UI thread, then thread affinity is maintained, but programming complexity and potential for bugs increase

Engineering Contradiction:
Improvethread affinityVSAvoidprogramming complexity
Core Design Contradiction:
ReliabilityVSDevice complexity

Solution Approach 1:

The patent implements self-service by enabling asynchronous operations to automatically manage their own thread affinity requirements. The synchronization context is captured and restored automatically by the runtime infrastructure, allowing developers to write simple asynchronous code without manually handling thread marshaling while still maintaining correct UI thread affinity

Inventive Principle:
Principle #25Self-service

Solution Approach 2:

The synchronization context acts as an intermediary that handles the complexity of thread management automatically. Instead of developers manually marshaling calls, the intermediary infrastructure captures the original thread's context and restores it when needed, shielding developers from the complexity while maintaining reliability

Inventive Principle:
Principle #24Intermediary (Mediator)

Data Source

PatentUS9880860B2Automatic return to synchronization context for asynchronous computations
Publication Date: 2018.01.30 MICROSOFT TECHNOLOGY LICENSING LLC
  • US9880860B2 patent drawing
  • US9880860B2 patent drawing
  • US9880860B2 patent drawing

AI summary

Architecture that includes an asynchronous library which remembers the synchronization context that initiated an asynchronous method call and when the request is completed, the library restores the synchronization context of the calling thread before executing a callback. This ensures that the callback executes on the same thread as the original asynchronous request. The callback to the asynchronous operation that asynchronous library provides automatically “jumps threads” to maintain thread affinity.