Board index » cppbuilder » How to run my app in single processor mode?

How to run my app in single processor mode?


2004-06-16 10:08:13 PM
cppbuilder81
Hi,
I have problem with hyper-threading and dual processor mode with my BCB6
application, how can I make my application run in single processor mode?
I have tried the following code in my main form. Perhaps this only makes the
main form run in single processor mode.
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
SetProcessAffinityMask(Handle, 0);
....
}
Best Regards,
Christer Strandh
 
 

Re:How to run my app in single processor mode?

"Christer Strandh Aragon" < XXXX@XXXXX.COM >wrote in
message news:40d053da$ XXXX@XXXXX.COM ...
Quote
void __fastcall TMainForm::FormCreate(TObject *Sender)
Do not use the OnCreate event in C++. It can be triggered before the
constructor, which is illegal in C++. Use the actual constructor instead.
Quote
SetProcessAffinityMask(Handle, 0);
You are specifying the wrong handle and mask. SetProcessAffinityMask()
expects a process handle, but you are giving it a window handle instead.
They two are not the same thing. You should be using GetCurrentProcess()
instead of the form's Handle property. Also, you should be calling
GetProcessAffinityMask() first to determine the mask that is available to
begin with, and then remove the unwanted bits from it before then passing it
back to SetProcessAffinityMask().
Gambit
 

Re:How to run my app in single processor mode?

Ok thanx för the input.
Sorry for my ignorance, but I cant get it to work, I put the
SetProcessAffinityMask code in the project .cpp file like this... My app.
hang when trying to start.
Not sure what time to execute SetProcessAffinityMask() after or before run?
have tried both.
Running BCB6 P4 with hyper-threading...
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
Application->Initialize();
SetProcessAffinityMask(GetCurrentProcess(), 0x001);
Application->CreateForm(__classid(TMainForm), &MainForm);
Application->Run();
)
//Christer
Quote
>void __fastcall TMainForm::FormCreate(TObject *Sender)

Do not use the OnCreate event in C++. It can be triggered before the
constructor, which is illegal in C++. Use the actual constructor instead.

>SetProcessAffinityMask(Handle, 0);

You are specifying the wrong handle and mask. SetProcessAffinityMask()
expects a process handle, but you are giving it a window handle instead.
They two are not the same thing. You should be using GetCurrentProcess()
instead of the form's Handle property. Also, you should be calling
GetProcessAffinityMask() first to determine the mask that is available to
begin with, and then remove the unwanted bits from it before then passing
it
back to SetProcessAffinityMask().


Gambit


 

{smallsort}

Re:How to run my app in single processor mode?

From my understanding, the process ID would be determined before the
entry point (WinMain), and will remain the same until the process
terminates, so you should be able to call GetCurrentProcess as the first
statement after WinMain
as far as sequence goes, it would be :
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
SetProcessAffinityMask(GetCurrentProcess(), 0x001);
Application->Initialize();
...
Christer Strandh Aragon wrote:
Quote
Ok thanx för the input.

Sorry for my ignorance, but I cant get it to work, I put the
SetProcessAffinityMask code in the project .cpp file like this... My app.
hang when trying to start.
Not sure what time to execute SetProcessAffinityMask() after or before run?
have tried both.
Running BCB6 P4 with hyper-threading...

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{

Application->Initialize();
SetProcessAffinityMask(GetCurrentProcess(), 0x001);
Application->CreateForm(__classid(TMainForm), &MainForm);
Application->Run();
)

//Christer