Thread: Mutex problem

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    48

    Mutex problem

    why does thread 1 gets suspended?
    Code:
    #include <windows.h>
    HANDLE mModuleManager;
    void Thread1() {
      while(1>0)
      { 
     WaitForSingleObject(mModuleManagerInput, INFINITE);
        mModuleManagerInput=CreateMutex(NULL,TRUE, "mModuleManagerInput");
        
         cout<<"test_working";
     pModuleManager->Out(pModuleManager->InputQueue.Read()->info, Char );
    
       ReleaseMutex(mModuleManagerInput); 
          } 
    }
    
    ...
    
    void Thread2()
    {   while (1>0)
       { cin>>Input; 
       cin.ignore();
        
        
        WaitForSingleObject(mModuleManagerInput, INFINITE);
      mModuleManagerInput=CreateMutex(NULL,TRUE, "mModuleManagerInput"); 
      
      ModuleManager.InputQueue.Input(CreateData((void*) Input, Char ));
    
          ReleaseMutex(mModuleManagerInput);
           
             }
    
    
    }

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Waiting on a mutex before creating it... A novel approach.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    48
    even if i create the mutex before the threads start thread1 doesn't show any kind of activity.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM