Re: Managed directsound problem under heavy CPU load
From: Vasanth Philomin (vasiATnospam.cs.umd.edu)
Date: 05/27/04
- Next message: Nihil: "Re: Real-time audio: soundcard to speaker"
- Previous message: Chris P. [MVP]: "Re: Real-time audio: soundcard to speaker"
- In reply to: Chris P. [MVP]: "Re: Managed directsound problem under heavy CPU load"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 27 May 2004 15:11:02 -0700
Hi,
As soon as i posted to the group, I tried out the old wave API and had the exact same problem. This kind of showed that it was not the directsound managed API but rather something basic having to do with threading that caused the problem. I then stumbled on Thread.Sleep() and everything worked great after that. Thanks for your comprehensive reply that explains the details clearly.
Vasi
----- Chris P. [MVP] wrote: -----
Well, I don't know crap about C# but I understand the senario.
Whenever you have badly behaved threads that consume 100% CPU there is going
to be a problem. I say badly behaved as there is a right way and a wrong
way to consume 100% CPU in a processing intensive thread. The wrong way is
to tightly loop and never yield. The correct way is to yield at least once
every 10-25ms so that other threads on the system can get their time slice.
You can yield by calling Sleep(), Sleep(0) technically will yield the
remainder of the time slice to another thread. However depending on the
frequency of the call you're probably better off calling Sleep() with a
small value such as Sleep(1) or Sleep(5). Your thread is still going to
likely consume near 100% CPU in the scheme of things. Also it is correct to
schedule the thread priorities like you did. It helps but isn't always a
total solution unless you make the threads play nice with each other. You
might get away with it if you set the heavy threads to only process on idle,
that way they should get preempted by everything.
- Next message: Nihil: "Re: Real-time audio: soundcard to speaker"
- Previous message: Chris P. [MVP]: "Re: Real-time audio: soundcard to speaker"
- In reply to: Chris P. [MVP]: "Re: Managed directsound problem under heavy CPU load"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|