locked
100% cpu utilization in call for WaitForSingleObject RRS feed

  • Question

  • Hi,

    I have a code in which I call "WaitForSingleObject" on an Event which is set by calling "SetEvent" in another process. As in the documentation for "WaitForSingleObject" is mentioned, the calling thread of "WaitForSingleObject" uses no processor time while waiting for the object state to become signaled or the time-out interval to elapse. Considering this I expect that the process which calls "WaitForSingleObject" have no cpu utilization while is in "WaitForSingleObject" call. But "Task Manager" shows a 100% cpu utilization for it.

    I would like to know where to ask this question. By the way, I am coding in C++ .

    Regards,

     

    Monday, February 7, 2011 2:46 PM

Answers

  • I think I know what might be happening. You don't actually check the return value of the WaitForSingleObject function. It looks like the WaitForSingleObject function is not actually waiting, and returning an error code. This will obviously cause a 100% CPU utilization due to an infinite loop.

    Monday, March 14, 2011 8:48 AM
  • Try the General Windows Development Issues forum.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Friday, February 11, 2011 12:44 AM

All replies

  • hi!

     

    Are you using SignalObjectAndWait ? I'd check if your instance is being created properly. You need to check in the handle is ok, are you using CreateThread ?

    Perhaps if you paste some code I can get an idea what 's happening. I have had some wierd  issues some time ago with those instructions and they were related to handle used.

     

    Best Regards,

     

    Roy

     



    :P
    Monday, February 7, 2011 4:24 PM
  • Hi,

    The code is as the following:

     

    HANDLE notifyEvent = CreateEvent(NULL, FALSE, FALSE, "notify");
    PROCESS_INFORMATION pi = createMyProcess(pathOfExe, cmdParameterLine);
    
    while(1)
    {
    WaitForSingleObject(notifyEvent, INFINITE);
    
    //...do somthing
    
    if(condition)
    {
    //do something
    }
    else
    {
    break;
    }
    
    } 
    
    The "notifyEvent" object will be set using "SetEvent" function, in the process created by "createMyProcess" function.

     

    Tuesday, February 8, 2011 6:18 AM
  • Hi,

    Isn't there anyone to tell me where is the right forum to ask my question?

    Regards,

    Wednesday, February 9, 2011 8:50 PM
  • Try the General Windows Development Issues forum.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Friday, February 11, 2011 12:44 AM
  • I think I know what might be happening. You don't actually check the return value of the WaitForSingleObject function. It looks like the WaitForSingleObject function is not actually waiting, and returning an error code. This will obviously cause a 100% CPU utilization due to an infinite loop.

    Monday, March 14, 2011 8:48 AM