views:

340

answers:

5

Is there any possible way of disabling multi core functionality on windows and just using a single core using C\C++? Any library that allows it? My application access one of our chip modules used to communicate with the host. We suspect someone else is accessing this module and changes it. The strange thing is that it only happens on a multi core system (Windows 7 64bit), and when you set windows to only use a single core (How to disable a core) everything works great.

It sounds to me that windows shouldn't allow any program to accomplish it programmatic, but I hope I'm mistaking.

EDIT: I'm not looking for suggestion regrading my threading skills. My problem is possibly more hardware or firmware related (Maybe the 2nd core is also accessing my chip module).

2nd EDIT: This is NOT a software problem! I only want to know if it's possible to disable multi core using C\C++. I don't seek threading advice as I'm 100% sure the problem doesn't lay there.

3rd EDIT: issue was SOLVED. The problem was with another process that my customer ran that accessing the same shared memory my application was accessing. As I previously mentioned, there was no problem with my thread and I never got the answer I looked for: A simple Yes or No regarding weather it is possible to disable one of the cores using C++. Processor affinity was not helpfull in my special case.

A: 

Unless your C/C++ library is using threading, I can't imagine how the number of cores could affect the runtime behavior. If your app does use threads, they will probably execute a bit differently on one core vs multiple cores, but if you can get an error on a multicore system you can probably get the same error on a single core system.

You can set processor affinity when launching your application. This locks your application to one processor. This may be a simple solution to the problem.

Eric J.
My library does using threading, but only a single thread access this module. There is no way another thread of mine has access to this module.
Eldad
@Eldad: It's still a simple thing to try out just to make sure. There's always the possibility that that single thread is sharing data with other threads and then ends up using corrupt data when accessing the module. Depending on the application's access pattern to the module, you might even try to set the processor affinity when the application is already running (using Task Manager).
Cwan
Tried it but it didn't work.
Eldad
+3  A: 

Even on a single core, you can be interrupted at any point. So I suspect your problem is to due to switching cores.

Douglas Leeder
+1  A: 

If you suspect the hardware driver isn't thread safe use the following to set interrupt affinity.

http://www.microsoft.com/whdc/system/sysperf/intpolicy.mspx

Einstein
A: 

Multithreading is a beast. Even "foolproof" sometimes bites you in the ...uhm... "back".

When you're using threads, you should do it right, because the OS has only a few rules it has to follow and can schedule your threads as it pleases. IIRC you can set priorities etc, maybe express something like preferences for certain CPUs in some OSes.

Even when you're using only one additional thread, you still have two, because the main app runs as well.

Maybe have a look at the debugging tools that specialize on thread debugging. Maybe they can help you with that.

As a start I'd add some mutexes or synchronized areas that access the module.

Patrick Cornelissen
+2  A: 

I think some workaround can be in setting affinity for main thread of your task for one core, than create threads with infinite loops for other cores and set them highest possible priority. But usually somthing wrong is in software if it cannot run on multicore hardware.

drlazy