Browse by Tags
All Tags »
Win32 (
RSS)
During the last couple of months, I have been updating the materials of the Developing Windows Concurrent Applications course. It is now an up-to-date four day ILT with lots of labs, demos, design patterns, and other practical materials to help C++ developers write their next great concurrent application for Windows. The target audience is C++ programmers with 1-2 years of experience writing Windows applications, but who haven’t necessarily seen how to create threads, queue work to the thread pool...
Visual Studio has had hardware-assisted memory access breakpoints for quite some time now—they are called data breakpoints and, unfortunately, can be used only for unmanaged code. WinDbg has a similar feature with the ba command, which is more flexible because it can be configured to fire when a memory location is read , not just written. (Of course, WinDbg does not have the managed/unmanaged limitation either, but you still have to exercise caution because managed objects may move in memory every...
You might have stumbled upon posts like this one that tell you there’s a simple solution for verifying that a memory location is OK for read/write/execution: Just use the “IsBadXxxPtr” family of functions that take a memory address and return a BOOL indicating if you can use the memory. It turns out (and I’m hardly the first to blog about it) that calling these functions causes more problems than it solves, and causes bugs rather than fixes them. Please heed the collective advice and stay away from...
Fairness with respect to synchronization mechanisms is a highly overrated property. When I talk about concurrency, parallelism, Windows synchronization and similar subjects, I’m often asked whether the specific algorithm, mechanism or feature is fair in some respect. First, let’s define fairness. I’ll use a simplistic yet rigorous definition to define a fair lock . (Other synchronization mechanisms may have fairness defined in a similar fashion.) To begin with, a lock is exactly what you think it...
A few months ago, we’ve taken a look at how you can extend your MDI or TDI application with an individual thumbnail and live preview for each tab (or document) that will be displayed in the Windows 7 taskbar. We’ve seen the temporary managed wrapper that makes this possible, and in the final 1.0 release of the Windows API Code Pack there is a more polished managed API that does the same thing. However, in this post I’d like to focus on the underlying details which you will have to deal with if you...
The managed synchronization mechanisms, including Monitor , WaitHandle.WaitAny , ManualResetEvent , ReaderWriterLock , Thread.Join , GC.WaitForPendingFinalizers and the rest of the family are not just a thin platform adaptation layer on top of the Win32 API. The CLR needs to know exactly which threads are currently waiting for a synchronization mechanisms for a variety of reasons. To mention two of them: In hosting scenarios, the CLR host might want to limit the ability of application threads...
Shortly after publishing my last post on converting native (C++ or Win32) exceptions to managed exceptions , I realized that some clarifications are in place. Trapping every Win32 exception and indiscriminately translating it to a managed exception is extremely dangerous. There are various scenarios in which a native exception is thrown to be caught, processed and handled – interfering with this process through a vectored exception handler might result in disastrous consequences. For example...
In a layered application consisting of managed upper layers and unmanaged lower implementation layers, you might frequently encounter the need to call unmanaged code, handle any exceptional conditions and reflect them to the upper layers as managed exceptions. This can be done manually, but fortunately as of Windows XP there is an approach that does not require wrapping every unmanaged call in an exception handler. This approach is vectored exception handling . A vectored exception handler...
Previously in the series we have examined the performance differences between concurrency patterns based on kernel synchronization (critical sections, events, mutexes etc.) and concurrency patterns based on wait-free synchronization (such as the interlocked family of operations). Kernel synchronization tends to be expensive if locks are frequently acquired and released because of the associated context switches, introducing anti-patterns such as lock convoys. Wait-free synchronization tends to be...
Last week I've resolved a simple "debugging" case by phone, and figured that it might benefit putting it online. Here's the approximate outline of the call: Customer: Sasha, we have a COM component registration that is failing because regsvr32 says it can't find the DLL. Myself: Where is it looking for that DLL? Customer: It doesn't matter where it's looking. We put the component in the System32 directory, but it still complained that it can't find it. Myself: [With...
Contrary to popular belief, Windows actually does a good job scheduling threads for execution across the available CPUs. (Yes, this was a controversial first sentence, but bear with me.) More often than not, smart developers tend to try to "outsmart" the operating system or framework that they happen to be using. In the particular case of thread scheduling, this "outsmarting" normally tends to fall in one of two categories: Not trusting the OS with thread CPU affinity . I.e.,...
After looking at managed and native deadlock diagnosis , we transitioned to a state of banging our heads against the table, which is a state familiar to many developers from their debugging all-nighters. How did we get in such a state? By issuing the modest "Batch Move" command on a set of pictures we wanted to move to a separate folder. The application responds in a way we have already seen before - it gets completely stuck. If you try deadlock diagnosis using the techniques I've shown...
Did you ever get a chance to blankly stare at a screen similar to the above, trying to recollect what your password really was? Security is great, and so is "Save password"; you try snooping for the application's configuration file or the registry where the password might be stored, only to find the application is storing it encrypted. If you're determined enough, you could start searching the process memory for strings to see if the password is stored somewhere in plaintext...
Debugging issues which have to do with synchronization objects, such as deadlocks and other types of hangs, has traditionally been a very difficult task. Normally left to consultants, it was a great source of income too. How does Windows actually keep track of synchronization objects? What does Vista have to do with this (as the title of the post suggests)? If this floats your boat, read on. The Win32 synchronization objects, as well as their managed counterparts (such as the .NET...
A few years ago, I recall needing to know (programmatically) which user has accessed a particular file. As part of a legacy system, this couldn't make the code base any worse. The idea was that there's a configuration file sitting on a network share; access to it is granted to only a single user at any given time. However, other users requesting access want to know why access is being denied - i.e., which user is holding them from accessing the file. This information...