Intel® C++ Compiler 16.0 User and Reference Guide

Microsoft Foundation Classes and Intel® Cilk™ Plus Programs

Note

This topic is for Windows* programmers only.

The Microsoft Foundation Classes (MFC) library depends upon thread local storage to map from its class wrappers to the GDI handles for objects. Because an Intel® Cilk™ Plus strand is not guaranteed to run on any specific OS thread, parallel code using Intel® Cilk™ Plus cannot safely call MFC functions.

There are two methods typically used to perform a computationally-intensive task in an MFC-based application:

Since the runtime system can switch operating system threads, Intel® Cilk™ Plus code must be isolated from code such as MFC that depends on Thread Local Storage.

To add a computation thread to an MFC program:

  1. Create a computation thread using operating-system facilities (_beginthreadex or AfxBeginThread). All the C++ code that is to be converted to Intel® Cilk™ Plus should run in this thread. The computation thread leaves the main (UI) thread available to run the message pump for processing window messages and updating the UI.

  2. Pass the handle (HWND) for the UI windows to the computation thread. When the computation thread needs to update the UI, it should send a message to the UI thread by calling PostMessage. PostMessage marshals and queues the message into the message queue associated with the thread that created the window handle. Do not use SendMessage. SendMessage is run on the currently executing thread, which is not the correct (UI) thread.

  3. Test the C++ program to ensure that the logic and thread management are correct.

  4. Add Intel® Cilk™ Plus constructs to the logic in the computation thread.

  5. Before terminating, the main (UI) thread should wait for the computation thread to complete, using WaitForSingleObject().

The QuickDemo sample program, supplied with the product, illustrates an Intel® Cilk™ Plus application using MFC.

Additional recommendations: