Thread: WaitForSingleObject does not allocating...

  1. #1
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768

    WaitForSingleObject does not allocating...

    What can make the WaitForSingleObject function to stop allocating me a thread...

    The first couple of threads have been allocated and ended successfully, but then it begins to timeout while waiting for a signal...

    ** Note: it's not the 30000ms timeout time.
    I've tried INFINITE but it just kept on waiting...

    ** Note: I'm using the same semaphore to create the threads.


    Thank you very much for all you help.

    Code:
    hSemaphore = OpenSemaphore(SYNCHRONIZE, 0, THREAD_SEMAPHORE);
    
    if (WaitForSingleObject(hSemaphore, 30000)==WAIT_TIMEOUT)
    {
       // error
    }
    
    ReleaseSemaphore(hSemaphore, 1, (long *)&dwSemCount);
    CloseHandle(hSemaphore);
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    To call ReleaseSemaphore, you need the SEMAPHORE_MODIFY_STATE access right. So change:
    Code:
    hSemaphore = OpenSemaphore(SYNCHRONIZE, 0, THREAD_SEMAPHORE);
    to:
    Code:
    hSemaphore = OpenSemaphore(SYNCHRONIZE  | SEMAPHORE_MODIFY_STATE, FALSE, THREAD_SEMAPHORE);

  3. #3
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    It did the trick, anonytmouse you never stop to amaze me.
    Thank you so much.

    But, what you are saying is that the semaphore could not be released?
    And by that wasting a thread? Am I right?
    Last edited by Devil Panther; 01-20-2006 at 03:54 AM.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Allocating a number of large 3d arrays in C
    By Surrender in forum C Programming
    Replies: 22
    Last Post: 08-19-2008, 08:36 AM
  2. Dynamically allocating 3D array
    By ssharish2005 in forum C Programming
    Replies: 8
    Last Post: 02-26-2008, 04:07 PM
  3. Help on waitforsingleobject(.....)
    By nhrraj in forum Windows Programming
    Replies: 2
    Last Post: 09-08-2007, 01:03 PM
  4. allocating memory screws up data being read in from file
    By Shadow12345 in forum C++ Programming
    Replies: 5
    Last Post: 12-06-2002, 03:23 PM
  5. Replies: 5
    Last Post: 11-24-2002, 11:33 PM