Delay() Question

Mac OSX specific forum
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Delay() Question

Post by chris319 »

I'm not sure if this is a bug.

The following code:

Code: Select all

Repeat

Delay(1)

Forever
causes the OS X Activity Monitor to show the process as "Not Responding", whereas in Windows it does not.

I am writing a program which involves repeated calls to either Delay() or WaitWindowEvent(). It works for a while, then locks up.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Delay() Question

Post by chris319 »

I think I have identified my problem. I was using a window timer and that seemed to have destabilized everything. Maybe the Mac window timer needs to be looked into. I concocted a workaround using threads and Delay().
WilliamL
Addict
Addict
Posts: 1255
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Delay() Question

Post by WilliamL »

That's interesting. I've used the window timer in simple programs and haven't had any problems. I remember reading that using Delay can interfere with the event loop but I can't remember how so I've been avoiding using Delay. Maybe combining the two were a problem.

If you can make a short piece of code demonstrating the problem, post it as a bug.
MacBook Pro-M1 (2021), Tahoe 26.1, PB 6.30b2
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Delay() Question

Post by chris319 »

Well, the program I'm using this in is kind of elaborate as it uses PortAudio which has a callback function to handle audio capture, so making a simple demo would not be straightforward. I will see if I can write a program with a timer specifically for the purpose of causing a failure.
WilliamL
Addict
Addict
Posts: 1255
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Delay() Question

Post by WilliamL »

I understand. I think we've all run into that dilemma.

The Mac version of PB is still evolving and I'm glad to hear you have a 'work-around'.
MacBook Pro-M1 (2021), Tahoe 26.1, PB 6.30b2
freak
PureBasic Team
PureBasic Team
Posts: 5950
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Delay() Question

Post by freak »

This is normal. If you use a GUI and you don't call WaitWindowEvent() on a regular basis, then the OS will assume that your program is not responding because... well, it actually is not responding to GUI messages. That is what WaitWindowEvent() does.
quidquid Latine dictum sit altum videtur
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Delay() Question

Post by chris319 »

My workarounds didn't work very well so I rewrote the program using PortAudio's blocking interface instead of the callback interface. Luckily it wasn't difficult to do. It is now much more stable. The code now looks like so:

Code: Select all

Repeat

//Call PortAudio function which returns when audio buffer is full

event = WindowEvent()

//Process window events

Forever
The CPU usage is about half of what it was using the PortAudio callback interface (now about 4% - 5%).
Post Reply