// Trouble launching 2nd thread from MainWindow, beginner //

This is a discussion on // Trouble launching 2nd thread from MainWindow, beginner // within the Windows Programming forums, part of the Platform Specific Boards category; Hi! I'm new to multithreading and developing in VC++ 6 directly with the win32 API. In console mode, the usual ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    1

    // Trouble launching 2nd thread from MainWindow, beginner //



    Hi!

    I'm new to multithreading and developing in VC++ 6 directly with the win32 API.

    In console mode, the usual code to create another thread and use it runs well in my system, but I have no success when using WinMain, like in the very simple code below:

    Code:
    int globalval;
    
    void __cdecl TestThread( void* param ){ globalval=10; }
    
    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE,
     PSTR szCmdLine, int nCmdShow )
    {
    globalval = 5;
    _beginthread( TestThread, 0, (void*)NULL ); 
    
    CreateMyWindows(hInstance);
    
    MSG mess;
    while( GetMessage(&mess,0,0,0) )
    {  
    TranslateMessage( &mess ); 
    DispatchMessage( &mess ); 
    } 
    
    return mess.wParam;
    }
    I go past the _beginthread call and it even returns a thread number, but apparently TestThread doesn't run at all, because globalval doesn't change. Then after the first call to GetMessage I get the error message "R6016 not enough space for thread data".

    Yes, I have VC6 with project set for run-time library "Debugging Multithread".

    Any ideas?

    Thanks a lot,

    Rick Trelles

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,660
    >> ...because globalval doesn't change
    No telling when you'll "see" the change. That's why you need proper synchronization when multiple threads access the same data.
    http://msdn.microsoft.com/en-us/library/ms810438.aspx
    http://msdn.microsoft.com/en-us/libr...89(VS.85).aspx

    >> I get the error message "R6016 not enough space for thread data"
    That error suggest that your thread indeed never run. Sounds like you have a memory leak and/or corruption elsewhere.

    gg

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Also, for windows programming, it is better to use CreateThread()
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple thread object model (my first post)
    By Codeplug in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2004, 10:34 PM
  2. Replies: 2
    Last Post: 04-12-2004, 01:37 AM
  3. Closing thread handles from within
    By Sang-drax in forum Windows Programming
    Replies: 6
    Last Post: 09-26-2003, 12:18 PM
  4. How to make a thread sleep or std::recv timeout?
    By BrianK in forum Linux Programming
    Replies: 3
    Last Post: 02-26-2003, 09:27 PM
  5. Multi-Thread Programming
    By drdroid in forum C++ Programming
    Replies: 6
    Last Post: 04-04-2002, 01:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21