Results 1 to 3 of 3

Thread: CPU Utilization = 100%

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Dallas,TX
    Posts
    170

    CPU Utilization = 100%

    I'm not sure if this is what *should* happen or there is a problem with the code, but the result is CPU Utilization for the app being 100%.

    Basically, the application uses overlapped serial COMM I/O and three threads for Rx, Tx, and Events. These three threads, do not cause any problems for CPU utilization as they implement WaitForMultipleObjects(), etc.

    Now, what the application does is basically constantly reads\writes to serial ports (3 in fact). The "datastream" is rather heavy...pretty much constant 115k baud data. Once the user "starts" the process, the program starts a single worker thread that uses a while loop to perform all the serial tasks...over and over. The main UI thread, waits for the user to stop (by selecting stop from the menu or whatever) and processes all normal windows messages. I have added a small Sleep() call to the while loop, but I can only sleep for about 50ms before the buffers start stacking up and eventually the program crashes.

    The problem is that once this thread begins processing, CPU Utilization hits the roof. Is this normal? What I should expect? Any ways to prevent this? Any advice?

    Thanks in advance!
    Phil

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Of course it is normal. If a thread constantly runs in a while loop it uses all available CPU power.

    To prevent the thread from hindering other apps you should make it a background thread. You do that by creating it suspended, set its priority and then resume it.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Dallas,TX
    Posts
    170
    Ok, cool...that's reassuring. Thanks...your very helpful as always!

    Phil

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width