-2

MSWindowsで2つのハードウェアCPUを使用してパフォーマンスを向上させる必要があります。私は次のコードを書きます:

#include "windows.h"

int main1(int argc, CHAR* argv[])
{
    // ...
}

int main2(int argc, CHAR* argv[])
{
    // ...
}

2つの主要な関数を記述します-1つはCPUごとに1つです。コンパイラは私に言います:

D:/MinGW/x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text+0x3d): undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status

私は何が間違っているのですか?2つのメインを作成して2つの異なるCPUで実行するにはどうすればよいですか?_tmain1, _tmain2どちらも役に立ちません。

4

3 に答える 3

4

main1つのプロセスに含めることができる関数は1つだけです。その関数から、複数のスレッドを開始できます。非常に短い例を次に示します。

#include <iostream>
#include <Windows.h>
#include <process.h>

void thread_func(void* v)
{
   std::cout << "Hello: " << *(int*)v << std::endl;
}

int main()
{
   int i = 1;
   ::_beginthread(thread_func, 0, &i);

   int i2 = 2;
   _beginthread(thread_func, 0, &i2);

   Sleep(1000);
}
于 2012-07-23T14:00:49.770 に答える
3

1つのメインを作成し、プロセッサアフィニティを設定する別のスレッドを開始します。

擬似コード:

int main1(){...}
int main2(){...}

int main()
{
  main2_thread = StartThreed( main2 );
  SetProcessorAffinity( this_thread, 0 );
  SetProcessorAffinity( main2_thread, 1 );
  main1();
}
于 2012-07-23T14:02:16.847 に答える
2

メインを1つだけ作成し、そこから複数のスレッドを起動します。または、複数のプロセスをフォークできる1つのメイン。

于 2012-07-23T14:01:56.457 に答える