Asynchronous Agents

Rick Molloy, one of the masterminds behind the new concurrency runtime (concrt) and parallel patterns library (PPL), has written an article in the latest issue of MSDN Magazine demonstrating the new asynchronous agents library with the classic dining philosophers problem.

Concurrent Affairs: Solving The Dining Philosophers Problem With Asynchronous Agents

Enabling C++ developers to write highly concurrent applications is a major focus of Visual Studio 2010. The beta release includes the Concurrency Runtime, parallel libraries, and development tools aimed at addressing several common problems preventing developers from unlocking the performance potential inherent to multicore hardware. Notably, this includes ensuring that developers can identify and take advantage of opportunities for concurrency in their code, productively manage shared state and its side effects, and not having to worry about building low-overhead concurrency infrastructure that is scalable at run time on a variety of hardware.

In this article, I'm going to demonstrate how to use the new Asynchronous Agents Library included as part of Visual C++ 2010 to manage the difficulties that can arise with shared state. To show you how this works, I will walk through an implementation of a classic concurrency problem: Djikstra's Dining Philosophers. You'll see how the actor-based programming construct of an agent in combination with asynchronous message-passing APIs can be used to provide a correct and easy to understand solution to this problem that doesn't rely directly on threading or synchronization primitives.

Enjoy!

Posted by KennyKerr with no comments

Lost Carrier Pigeon

What do you when a carrier pigeon lands in your back yard seemingly lost?

It has bracelets around its feet with numbers but no email address.   :)

It’s pretty tame and let me pick it up to inspect its markings.

Posted by KennyKerr with 3 comment(s)

Windows with C++: Introducing Direct2D

I’ve been away from my computer for a few days working on a house renovation project and didn’t notice that my latest Windows with C++ column came out until the mail man delivered a copy of the June 2009 issue of MSDN Magazine.

In this issue I introduce a new technology that I’m very excited about. I’ve been waiting for Direct2D for some time. When Microsoft started pushing WPF as the “one true path” (TM) I just couldn’t persuade myself to buy the sales pitch. If you felt the same way then read on. This just might make your day.

Windows with C++: Introducing Direct2D

With the introduction of Windows Vista a few years ago, it was clear that the era of the Windows Graphics Device Interface (GDI) was coming to an end. GDI, even with the help of GDI+, had been showing its age especially when compared to the superior graphics capabilities of Windows Presentation Foundation (WPF). As if that weren't enough, GDI lost its hardware acceleration while WPF took advantage of Direct3D's abundance of hardware acceleration.

However, if you want to develop high-performance and high-quality commercial applications, you'll still look to C++ and native code to deliver that power. That's why few things excite me more about Windows 7 than the introduction of Direct2D and DirectWrite. Direct2D is a brand new 2D graphics API designed to support the most demanding and visually rich desktop applications with the best possible performance. DirectWrite is also a brand-new API that complements Direct2D and provides hardware-accelerated text, when used with Direct2D, and high-quality text layout and rendering with advanced support for OpenType typography and ClearType text rendering.

In this article, I will explore these new technologies and give you an idea of why it matters and how you can start using them today.

Big thanks to Mark Lawrence and Ben Constable, from the Direct2D team, for their feedback on the article as well as for providing a side bar discussing rendering performance.

Stay tuned for more Direct2D articles in my upcoming Windows with C++ columns.

If you’re looking for one of my previous articles here is a complete list of them for you to browse through.

Produce the highest quality screenshots with the least amount of effort! Use Window Clippings.

Posted by KennyKerr with 3 comment(s)

WTL 8.1 is coming!

After almost two years of silence there appears to be activity around WTL again. Of course this makes sense since Windows 7 is almost done. I just noticed build 8.1.9127 posted over on SourceForge.NET.

For starters it now builds cleanly by internally suppressing warnings against the use of unsafe CRT functions. I have got into the habit of including WTL 8.0 in my precompiled header as follows:

#pragma warning(push)
#pragma warning(disable:4996) // WTL still uses some unsafe CRT functions
#include <atlapp.h>
.
.
.
#pragma warning(pop)

Well no more. To be precise, it still uses those unsafe functions but the warnings are now suppressed internally and explicitly around those functions so that we don’t have to deal with it ourselves.

Wrappers have also been added for the Desktop Window Manager API as well as the support needed to subclass and double-buffer the painting of controls on glass. For more information on the DWM API as well as the issues with controls on glass you can read my articles here and here.

Beyond that it looks like this is just the initial placeholder for what will become the 8.1 release of WTL.

Posted by KennyKerr with no comments

Visual Studio 2010 and .NET Framework 4 Beta 1 are here!

Microsoft has finally released an update to the Visual Studio 2010 preview build that showed so much promise but unfortunately was so unreliable. If you have an MSDN subscription just head over to subscriber downloads and start downloading now!

Interestingly (and thankfully) they appear to have reduced the number of SKUs. There is only “Professional” and “Team Suite”.

Posted by KennyKerr with no comments

Resolving Windows Sleep Problems

This is more of a reminder to myself but it may come in handy for you.

Whenever I reinstall Windows I always make sure to install the latest chipset drivers from Intel which tends to make things run more smoothly, especially on laptops, with regards to power management.

On my desktop computer there is one more step I need to take before it will correctly sleep and stay asleep but I always seem to forget this and spend some time wondering which driver or device isn’t letting the computer go to sleep. Nine times out of ten though it’s not as a result faulty or missing drivers but is actually “by design”.

Wired network adapters seem to always be configured to Wake-on-LAN by default. This may be useful for corporate networks but is terribly annoying for home computers where it gives the appearance that Windows simply can’t sleep reliably when in fact it is the network adapter that keeps waking up the computer when network traffic is received.

Anyway the solution is simple, simply uncheck the “Allow this device to wake the computer” option for you wired network adapter:

 

Hope that helps.

Posted by KennyKerr with 5 comment(s)

C++ Exception Handling

A while ago I made a passing remark on my blog that I prefer not to use exceptions in native code. Some readers asked me to justify this position and I’ve been a bit reluctant to do so only because it’s a lengthy argument that I’m sure will bring a lot of passionate responses that I don’t really have the time to deal with. I was reminded of this again last night when I walked past one of our bookshelves at home and picked up my copy of John Robbins’ excellent debugging book and noticed that it has a chapter on crash handlers within which John does a good job of covering many of the reasons why I don’t use exception handling in native code. If you’re interested in this topic I would encourage you to read John’s book.

Of course I still write “exception safe” code in the sense that I use “resource acquisition is initialization” or constructors and destructors to scope resources, avoid side effects in functions, define invariants, etc. but this is just good practice to write simple and correct code whether or not exceptions are in play.

The Visual C++ compiler actually lets you disable exception handling in your code which by the way improves performance and reduces code size. Here’s how:

 

The story is very different for managed code where exceptions are very much an integral part of the runtime and thus cannot be avoided. Of course managed exceptions more than make up for the pitfalls with exception handling by providing a standard base class with exception information including the call stack at the time an exception was thrown thus greatly improving the ability for developers to track down bugs.

 

Posted by KennyKerr with 15 comment(s)

Exciting Changes

I’ve made a few changes to my professional life. I’ve had the opportunity to work with some really talented developers in London and I’m sorry to say goodbye to them. I’ll talk more about that in the coming weeks and months but one of the outcomes is that I’ll have much more time for my software projects. To unwind from employment (e.g. slavery :) ) I took Karin and the kids camping and boy did things change in the world of Microsoft technology in just one week. Here are just some of the announcements.

Windows 7 (and Server) Release Candidate – by far the biggest news is the arrival of the Windows 7 RC. You can get it from your MSDN subscription along with the latest Windows SDK. The server version of Windows 7, called Windows Server 2008 R2, is also available. Interestingly, the Windows SDK is now split across platforms.

Office 2007 Service Pack 2 – the next service pack for Office 2007 is out so if there was ever any doubt that Office 2007 is ready for mass corporate adoption you’re now all out of excuses!  :)

Windows Vista Service Pack 2 – the second service pack for Windows Vista has also been released.

Virtual PC Beta – we all thought it was dead but here comes a new version. It looks like this will be the last version of Virtual PC before Hyper-V is rolled into all versions of Windows. In other words I expect Windows 8 to include Hyper-V just as Windows Server now does. This is in much the same was as Remote Desktop Services first debuted in Windows Server and is now included in all editions of Windows.

If you really need XP support then you may want to take a look at Windows 7’s XP Mode, which allows you to run Windows XP applications on your Windows 7 desktop. This uses the new version of Virtual PC but will eventually be based on Hyper-V.

As a (native) C++ developer there’s just so much to be excited about when you consider Windows 7. I’ve started covering Windows 7 technology in my Windows with C++ column in MSDN Magazine and you can expect many more articles focused on Windows 7 in the coming months. Here are just a few that I’m particularly interested in:

Virtual Disk API – I covered this in the April 2009 issue of MSDN Magazine.

Direct2D – I have an introduction to Direct2D in the upcoming June 2009 issue of MSDN Magazine.

In addition there are new APIs for advanced text rendering and typography, powerful user interface animation, ribbon user interface, web services clients and servers, and much more. And all of this is designed for C++ developers! I’ll be covering many of these in upcoming articles.

As I’ve said before, these are exciting times for a C++ developer on Windows.

 

Posted by KennyKerr with 3 comment(s)

Another year in the MVP Award program!

Thanks to all the talented people at Microsoft.

There's never been a more exciting time to be a C++ developer on the Windows platform!

Posted by KennyKerr with 3 comment(s)

Windows with C++: The Virtual Disk API in Windows 7

My latest Windows with C++ column in the April 2009 issue of MSDN Magazine is now online:

The Virtual Disk API in Windows 7

As I write this, the Windows 7 beta has been available for a few days, and I must say there is a lot to like. As usual, I took a look under the hood to see what is new in the Windows SDK. Windows 7 is very much a minor release as far as the SDK is concerned, and that's a good thing. The fundamentals of writing native C++ applications for Windows 7 have not changed much compared to the way they changed for Windows Vista. Having said that, however, Windows 7 has some completely new features that are sure to interest anyone looking to take advantage of the platform.

One of these features is the Virtual Disk API. Although designed with other formats in mind, the Virtual Disk API in the Windows 7 beta is very much geared toward the Microsoft Virtual Hard Disk (VHD) format popularized by virtualization products from Microsoft such as Hyper-V and Virtual PC.

Enjoy!

 

If you’re looking for one of my previous articles here is a complete list of them for you to browse through.

Produce the highest quality screenshots with the least amount of effort! Use Window Clippings.

Posted by KennyKerr with no comments
More Posts Next page »