RobinI
RobinI

Reputation: 47

Limiting processor count for multi-threaded applications

I am developing a multi threaded application which ran fine on my development system which has 8 cores. When I ran it on a PC with 2 cores I encountered some synchronization issues.

Apart from turning off hyper-threading is there any way of limiting the number of cores an application can use so that I can emulate single and dual core environments for testing & debugging.

My application is written in C++ using Visual Studio 2010.

Upvotes: 0

Views: 106

Answers (2)

egur
egur

Reputation: 7960

You want the SetProcessAffinityMask function or the SetThreadAffinityMask function.

The former works on the whole process and the latter on a specific thread.

You can also limit the active cores via the Windows Task Manager. Right click on process name and select "Set Affinity".

Upvotes: 2

paxdiablo
paxdiablo

Reputation: 881253

We always test in virtual machines nowadays since it's so easy to set up specific environments with given limitations.

For example, VMWare easily allows you to limit the number of processors in use, how much memory there is, hard disk sizes, the presence of USB or floppies or printers and all sorts of other wondrous things.

In fact, we have scripts which do all the work at the push of a button, from restoring the VM to a known initial state, then booting it up, installing the code over the network, running a test cycle then moving the results to an analysis machine on the network as well.

It greatly speeds up and simplifies the testing regime.

Upvotes: 3

Related Questions