Raymond Chen continues his series on sharing the result of a single Windows Runtime IAsyncOperation among multiple coroutines, suggesting a straightforward approach where each coroutine simply takes turns trying to access the operation's result.
devblogs-microsoft-com-oldnewthing
30 items from devblogs-microsoft-com-oldnewthing
The article discusses techniques for caching the result of a single Windows Runtime IAsyncOperation so that multiple coroutines can share it, focusing on how to determine when the cached result is still valid.
The blog post explains why C++/WinRT does not allow awaiting a Windows Runtime asynchronous operation more than once, contrasting with C# and JavaScript. This difference stems from varying design philosophies: C++/WinRT follows the C++ principle of move semantics and single ownership, whereas C# and JavaScript adopt a more forgiving approach that supports multiple awaits.
Raymond Chen proposes a hypothetical redesign of C#'s System.Diagnostics.Process class to prevent misuse of properties that are only valid for processes started by the caller, by placing them in a separate object accessible only after calling Start.
A COM STA thread must pump messages when idle, but if the thread is never idle—because it performs continuous work or exits quickly—message pumping may not be necessary, which explains why some sample code omits it.
The article explains that Win32 structures cannot be directly used from the Windows Runtime, but suggests workarounds to approximate their functionality.
The classic TreeView control allows sorting by display name or by the lParam value, but not both simultaneously. To achieve combined sorting, you must calculate one value from the other rather than relying on the built-in sort features.
The ERROR_ARENA_TRASHED error code indicates that the storage control blocks were destroyed. This post from The Old New Thing explores the history behind this error code.
A blog post notes that a particular detail has been reported incorrectly since the day it was written, using this as an example of how the parity flag in debugging is no longer a concern for developers.
A developer encountered a case where CreateFileMapping always returned ERROR_ALREADY_EXISTS. The explanation is straightforward: the error occurs because a file mapping with that name already exists.
The article explains that Windows client editions on 32-bit x86 systems limit RAM to 4 GB for compatibility reasons, as many older drivers and applications were not designed to handle memory above that threshold.
A constant-space linear-time algorithm for deleting all but the 10 most recent files in a directory
0.5Raymond Chen presents a constant-space, linear-time algorithm to delete all but the ten most recent files in a directory, using a priority queue (min-heap) as the core data structure to efficiently track and discard older files during a single pass.
Raymond Chen investigates a debugging case where an application hung when the user changed keyboard layouts, tracing the issue to a deadlock caused by thread synchronization and message processing order.
The article provides additional guidance on controlling handle inheritance in the CreateProcess function, specifically focusing on the technique of placing handles in a private container to manage which handles are inherited by child processes.
The post explains that developers can gain more confidence when tracking file renames via ReadDirectoryChangesW by tracking the file ID.
When upgrading resource strings to Unicode, developers must include the L prefix; otherwise, the string will be mapped back down to the 8-bit code page.
Raymond Chen explains why altering API behavior based on the SDK version you link against is impractical, noting that static libraries cannot adapt to such runtime checks, making the approach unreliable.
A dispute over the TAB key highlights a mismatch between Microsoft and IBM organizational structures
1.0Raymond Chen recounts a historical conflict between Microsoft and IBM over the behavior of the TAB key in OS/2's dialog boxes, illustrating how Microsoft's flat, team-oriented structure clashed with IBM's hierarchical, manager-driven organization. The dispute, which eventually reached upper management, stemmed from differing approaches to user interface design and decision-making authority.
The blog post explains that there is no need to inform Windows that you are writing a binary file, because at the file system level all files are binary.
This post continues a series on building a cross-process reader/writer lock, focusing on handling the scenario where a process holding the lock is terminated, requiring recovery mechanisms for the abandoned lock state.
Raymond Chen continues his series on cross-process reader/writer locks, this time addressing the problem of "grabby" readers that prevent writers from making progress. He explores solutions using Windows synchronization primitives like semaphores and events to ensure fair turn-taking between readers and writers.
Raymond Chen continues his series on cross-process reader/writer locks by addressing fairness, ensuring exclusive (write) acquisitions get a fair chance against repeated shared (read) acquisitions to prevent writer starvation.
Raymond Chen begins a series on developing a cross-process reader/writer lock with a limited number of readers, introducing a semaphore as the starting mechanism to manage concurrent access.
The article examines what happens when a C function receives fewer register parameters than expected across different CPU architectures, concluding the outcome is always problematic but especially severe on Itanium.
The article discusses techniques for defending against exceptions within a scope_exit RAII (Resource Acquisition Is Initialization) type, but ultimately questions whether the effort is worthwhile.
Raymond Chen discusses a Windows crash caused by an uninstaller that injected code into Explorer.exe, then removed files the injected code depended on, causing a crash. He analogizes this to inadvertently destroying a staircase while standing on it, highlighting the dangers of code injection into critical system processes.
The article discusses fractal page mapping, a technique for mapping page tables into memory using the page tables themselves. This approach allows the operating system to access its own page table structures through the virtual memory system it manages.
The article discusses why XOR became the most popular idiom for zeroing out a register in assembly programming, rather than using subtraction. It examines the historical and technical reasons behind this convention.
When working with 24-bit-per-pixel formats on video cards with bank-switched memory, code had to use aligned memory accesses despite the pixels themselves not being aligned. This requirement was necessary due to the hardware constraints of bank-switched video memory architectures.
The article explains that when a C++ compiler reports an error about code you didn't write, you should investigate who actually wrote that code. This helps in understanding misleading error messages like "illegal use of ->" when no arrow operator appears in your source.