c ++线程不会在主线程之外调用

时间:2013-06-13 08:58:11

标签: multithreading visual-c++ createthread

我整天都在研究一个大项目,以找出最重要的部分是相当有用的。我已经尝试了一切来解决它。

我将在下面发布一个代码示例,以显示我的代码中发生了什么。 很抱歉在这里发布了这么多代码,但是真的需要了解我做得更好。

我之前从未遇到过这个问题。 我不能再从任何地方调用线程了。 文件包括:

functions.h
defines.h
structs.h
typedefs.h
menu.h

void button_monitor(int ClientIndex)
{
      int Down = _Buttons(ClientIndex);
      if(Down & (LB) && Down & (RB) && verified[ClientIndex]==true)
      {
        //Let's say we created a thread here; it will fail. When I say fail "I mean nothing at all actually happens I can call it all day long"
        //CreateThread(0,0,test_thread,0,0,0);
      }
 }

DWORD WINAPI test_thread(LPVOID)
{
             //the test thread
}

DWORD WINAPI main_thread(LPVOID)
{
    for(;;)
    {
        //Let's say we created a thread here; it will fail. When I say fail "I mean nothing at all actually happens I can call it all day long"
        //CreateThread(0,0,test_thread,0,0,0);
        if (Dvar_GetBool("cl_ingame"))
        {
         CreateThread(0,0,doInfections,0,0,0);
         for(int ClientIndex = 0; ClientIndex < 18;ClientIndex++)
         {
           button_monitor(ClientIndex);
         }
        }
    }
}






BOOL WINAPI DllMain(HANDLE hInstDLL, DWORD reason, LPVOID lpReserved)
{
  switch(reason)
  {
    case DLL_PROCESS_ATTACH:
      CreateThread(0,0,main_thread,0,0,0);
      break;
  }
}

任何人的帮助/建议都会超级惊人。我被困住了几个小时。

0 个答案:

没有答案