Xojo Conferences
XDCMay2019MiamiUSA

Are "protected" threads something possible in RB (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: FR: Interfaces should be satisfiable by superclass methods
Next thread: Extends Editfield issue


Are "protected" threads something possible in RB   -   lveillette
  Re: Are "protected" threads something possible in RB   -   Daniel Stenning
  Re: Are "protected" threads something possible in RB   -   Daniel Stenning
  Re: Are "protected" threads something possible in RB   -   Dave Addey
   Re: Are "protected" threads something possible in RB   -   Charles Yeomans
    Re: Are "protected" threads something possible in RB   -   Chris Little
   Re: Are "protected" threads something possible in RB   -   Norman Palardy
    Re: Are "protected" threads something possible in RB   -   Daniel Stenning
  Re: Are "protected" threads something possible in RB   -   Frank Condello
  Re: Are "protected" threads something possible in RB   -   Frank Condello
  Re: Are "protected" threads something possible in RB   -   lveillette

Are "protected" threads something possible in RB
Date: 26.11.07 22:12 (Mon, 26 Nov 2007 16:12:40 -0500)
From: lveillette
I have to write many applications that need to generate audio and or vide in
realtime and I can't believe how annoying it is to deal with the whole event
queue system in RB that makes even threads stops when even so much as
touching a control... That's so OS9!!!

As I understand it (but I may be wrong) the only wat to circumvent this is
to split an application in two, with more or less predictable results on
performance.

So what I'm wondering is would it be possible to have more control over
threads IN RB? I'm thinking of 3 features in particular:

- a way to make a really protected thread that is still attached to the main
application, but runs regardless of controls or other events being touched
or fired in the rest of the application

- a way to balance the activity of such a thread and say, make sure that it
always use at least a certain percentage of CPU time, regardless of what's
going on in the main or other applications runnig at the same time

- a way to control on what core the thread runs for muticore systems, that
way we could tell an application to stay on one core and keep the other free
for other processes.

Is it worth posting a feature request?

Thanx

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Are "protected" threads something possible in RB
Date: 26.11.07 23:25 (Mon, 26 Nov 2007 22:25:49 +0000)
From: Daniel Stenning
Frank Condello has an RB class "AsyncDragWindow" which gets around some of
the silly issues you mention with regard to RB events blocking threads.

Google his site "Chaoticbox" for further details.

I seem to remember there was something similar to handle menu issues as well
maybe from frank, possibly from Charles Yeomans.

In any case, as someone else who ha to code for audio streams I sympathise.

I have ended up using the Monkeybread Audio Stream classes, which allow you
to pass audio blocks to the MBS CoreAudioStream class In the MAIN RB thread.

This gets around the issues you mention regarding pre-emptve threading to
some degree, by using a timer event to push audio. Youll need a different
ancestor timer class that the MBS plugins provide - called
"CarbonEventsTimerMBS". This operates similarish to the RB timer, but less
prone to the crappy blocking issues you mention.

Hope this helps.

Dan Stenning

On 26/11/07 21:12, "lveillette" <<email address removed>> wrote:

> I have to write many applications that need to generate audio and or vide in
> realtime and I can't believe how annoying it is to deal with the whole event
> queue system in RB that makes even threads stops when even so much as
> touching a control... That's so OS9!!!
>
> As I understand it (but I may be wrong) the only wat to circumvent this is
> to split an application in two, with more or less predictable results on
> performance.
>
> So what I'm wondering is would it be possible to have more control over
> threads IN RB? I'm thinking of 3 features in particular:
>
> - a way to make a really protected thread that is still attached to the main
> application, but runs regardless of controls or other events being touched
> or fired in the rest of the application
>
> - a way to balance the activity of such a thread and say, make sure that it
> always use at least a certain percentage of CPU time, regardless of what's
> going on in the main or other applications runnig at the same time
>
> - a way to control on what core the thread runs for muticore systems, that
> way we could tell an application to stay on one core and keep the other free
> for other processes.
>
> Is it worth posting a feature request?
>
> Thanx
>
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
> Search the archives:
> <http://support.realsoftware.com/listarchives/lists.html>

Cheers,
Dan



_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Are "protected" threads something possible in RB
Date: 26.11.07 23:29 (Mon, 26 Nov 2007 22:29:36 +0000)
From: Daniel Stenning
There are existing FRs on this theme ( some probably from me )

Even when we get a true way of integrating system pre-emptive threads into
RB apps you'll still need to be careful. Leopard adds an MP API to the
frameworks, which I would hope one way to find its way into RB too, but sine
RB has its own thrading model, which is basically co-operative, I woudlnt
hold your breath.

On 26/11/07 21:12, "lveillette" <<email address removed>> wrote:

>
> - a way to control on what core the thread runs for muticore systems, that
> way we could tell an application to stay on one core and keep the other free
> for other processes.
>
> Is it worth posting a feature request?

Cheers,
Dan



_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Are "protected" threads something possible in RB
Date: 27.11.07 23:11 (Tue, 27 Nov 2007 22:11:29 +0000)
From: Dave Addey
Hi there,

I've wrestled with this for ages, and the only way I managed to do it (in
order to run QuickTime calls on a true pre-emptive background thread) was to
create a custom plugin in Xcode to launch a new Carbon MPThread. This
background thread then communicates with the main (REALbasic) thread via
Carbon Events, as described here:

http://developer.apple.com/technotes/tn/tn2125.html

This requires a lot of custom code, but it does work.

Every other approach I tried - including firing off the pre-emptive threads
via declares from REALbasic, with a module method as the callback for the
thread - would fail for some reason or other. If you really want to use
pre-emptive threads, be prepared to get your hands dirty with plugins.

Dave.

> From: lveillette <<email address removed>>
> Reply-To: REALbasic NUG <<email address removed>>
> Date: Mon, 26 Nov 2007 16:12:40 -0500
> To: "<email address removed>"
> <<email address removed>>
> Conversation: Are "protected" threads something possible in RB
> Subject: Are "protected" threads something possible in RB
>
> I have to write many applications that need to generate audio and or vide in
> realtime and I can't believe how annoying it is to deal with the whole event
> queue system in RB that makes even threads stops when even so much as
> touching a control... That's so OS9!!!
>
> As I understand it (but I may be wrong) the only wat to circumvent this is
> to split an application in two, with more or less predictable results on
> performance.
>
> So what I'm wondering is would it be possible to have more control over
> threads IN RB? I'm thinking of 3 features in particular:
>
> - a way to make a really protected thread that is still attached to the main
> application, but runs regardless of controls or other events being touched
> or fired in the rest of the application
>
> - a way to balance the activity of such a thread and say, make sure that it
> always use at least a certain percentage of CPU time, regardless of what's
> going on in the main or other applications runnig at the same time
>
> - a way to control on what core the thread runs for muticore systems, that
> way we could tell an application to stay on one core and keep the other free
> for other processes.
>
> Is it worth posting a feature request?
>
> Thanx
>
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
> Search the archives:
> <http://support.realsoftware.com/listarchives/lists.html>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Are "protected" threads something possible in RB
Date: 27.11.07 23:27 (Tue, 27 Nov 2007 17:27:06 -0500)
From: Charles Yeomans
Of course this just tempts me to try to work it out without plugins...

Charles Yeomans

On Nov 27, 2007, at 5:11 PM, Dave Addey wrote:

> Hi there,
>
> I've wrestled with this for ages, and the only way I managed to do
> it (in
> order to run QuickTime calls on a true pre-emptive background
> thread) was to
> create a custom plugin in Xcode to launch a new Carbon MPThread. This
> background thread then communicates with the main (REALbasic)
> thread via
> Carbon Events, as described here:
>
> http://developer.apple.com/technotes/tn/tn2125.html
>
> This requires a lot of custom code, but it does work.
>
> Every other approach I tried - including firing off the pre-emptive
> threads
> via declares from REALbasic, with a module method as the callback
> for the
> thread - would fail for some reason or other. If you really want
> to use
> pre-emptive threads, be prepared to get your hands dirty with plugins.
>
> Dave.
>
>> From: lveillette <<email address removed>>
>> Reply-To: REALbasic NUG <<email address removed>>
>> Date: Mon, 26 Nov 2007 16:12:40 -0500
>> To: "<email address removed>"
>> <<email address removed>>
>> Conversation: Are "protected" threads something possible in RB
>> Subject: Are "protected" threads something possible in RB
>>
>> I have to write many applications that need to generate audio and
>> or vide in
>> realtime and I can't believe how annoying it is to deal with the
>> whole event
>> queue system in RB that makes even threads stops when even so much as
>> touching a control... That's so OS9!!!
>>
>> As I understand it (but I may be wrong) the only wat to circumvent
>> this is
>> to split an application in two, with more or less predictable
>> results on
>> performance.
>>
>> So what I'm wondering is would it be possible to have more control
>> over
>> threads IN RB? I'm thinking of 3 features in particular:
>>
>> - a way to make a really protected thread that is still attached
>> to the main
>> application, but runs regardless of controls or other events being
>> touched
>> or fired in the rest of the application
>>
>> - a way to balance the activity of such a thread and say, make
>> sure that it
>> always use at least a certain percentage of CPU time, regardless
>> of what's
>> going on in the main or other applications runnig at the same time
>>
>> - a way to control on what core the thread runs for muticore
>> systems, that
>> way we could tell an application to stay on one core and keep the
>> other free
>> for other processes.
>>
>> Is it worth posting a feature request?
>>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Are "protected" threads something possible in RB
Date: 28.11.07 02:50 (Tue, 27 Nov 2007 20:50:59 -0500)
From: Chris Little
I think it would be possible. It's the Carbon events that are key since they
only run at "nice" times.

Chris

on 11/27/07 5:27 PM, Charles Yeomans at <email address removed> wrote:

> Of course this just tempts me to try to work it out without plugins...
>
> Charles Yeomans
>
> On Nov 27, 2007, at 5:11 PM, Dave Addey wrote:
>
>> Hi there,
>>
>> I've wrestled with this for ages, and the only way I managed to do
>> it (in
>> order to run QuickTime calls on a true pre-emptive background
>> thread) was to
>> create a custom plugin in Xcode to launch a new Carbon MPThread. This
>> background thread then communicates with the main (REALbasic)
>> thread via
>> Carbon Events, as described here:
>>
>> http://developer.apple.com/technotes/tn/tn2125.html
>>
>> This requires a lot of custom code, but it does work.
>>
>> Every other approach I tried - including firing off the pre-emptive
>> threads
>> via declares from REALbasic, with a module method as the callback
>> for the
>> thread - would fail for some reason or other. If you really want
>> to use
>> pre-emptive threads, be prepared to get your hands dirty with plugins.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Are "protected" threads something possible in RB
Date: 28.11.07 04:33 (Tue, 27 Nov 2007 20:33:28 -0700)
From: Norman Palardy

On 27-Nov-07, at 3:27 PM, Charles Yeomans wrote:

> Of course this just tempts me to try to work it out without plugins...
>
> Charles Yeomans

Wouldn't that be problematic since the runtime isn't re-entrant in so
many ways ?
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Are "protected" threads something possible in RB
Date: 28.11.07 14:23 (Wed, 28 Nov 2007 13:23:14 +0000)
From: Daniel Stenning
If we're simply talking about the needs of true pre-emptive threading for
streaming of audio data, so far at least I got around most of the issues by
using a timer ( non pre-emptive ) that allows me to push audio data blocks
on to a FIFO in MBS CoreAudioStreamPlayer.

This way only the MBS CoreAudioStreamPlayer plugin class actually respond
to callbacks from the pre-emptive system CoreAudio thread independently from
the work I do to create the audio stream blocks.

All my code can sit in the Main RB thread. This has the wonderful advantage
that debugging becomes possible, breakpoints work etc. The previous method
I used, whereby I provided a callback to the the CoreAudio Audio thread, was
fraught with problems.

On 28/11/07 03:33, "Norman Palardy" <<email address removed>>
wrote:

>
> On 27-Nov-07, at 3:27 PM, Charles Yeomans wrote:
>
>> Of course this just tempts me to try to work it out without plugins...
>>
>> Charles Yeomans
>
> Wouldn't that be problematic since the runtime isn't re-entrant in so
> many ways ?
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
> Search the archives:
> <http://support.realsoftware.com/listarchives/lists.html>

Cheers,
Dan



_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Are "protected" threads something possible in RB
Date: 27.11.07 00:10 (Mon, 26 Nov 2007 18:10:56 -0500)
From: Frank Condello

On 26-Nov-07, at 5:25 PM, Daniel Stenning wrote:

> Frank Condello has an RB class "AsyncDragWindow" which gets around
> some of
> the silly issues you mention with regard to RB events blocking
> threads.
>
> Google his site "Chaoticbox" for further details.
>
> I seem to remember there was something similar to handle menu
> issues as well
> maybe from frank, possibly from Charles Yeomans.

If you start up a Carbon timer (provided by a plugin or with few
simple declares) then stick "App.YieldToNextThread" in the callback,
Rb threads will no longer be blocked by UI interaction. You just
gotta take care to disable or throttle back the timer when
appropriate to free up some CPU resources. For the best results I'd
recommend this hack plus the AsyncDragWindow hack.

Frank.
<http://developer.chaoticbox.com/>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Are "protected" threads something possible in RB
Date: 27.11.07 00:18 (Mon, 26 Nov 2007 18:18:07 -0500)
From: Frank Condello

On 26-Nov-07, at 6:10 PM, Frank Condello wrote:

>
> On 26-Nov-07, at 5:25 PM, Daniel Stenning wrote:
>
>> Frank Condello has an RB class "AsyncDragWindow" which gets around
>> some of
>> the silly issues you mention with regard to RB events blocking
>> threads.
>>
>> Google his site "Chaoticbox" for further details.
>>
>> I seem to remember there was something similar to handle menu
>> issues as well
>> maybe from frank, possibly from Charles Yeomans.
>
> If you start up a Carbon timer (provided by a plugin or with few
> simple declares) then stick "App.YieldToNextThread" in the callback,
> Rb threads will no longer be blocked by UI interaction. You just
> gotta take care to disable or throttle back the timer when
> appropriate to free up some CPU resources. For the best results I'd
> recommend this hack plus the AsyncDragWindow hack.

I should add that although the App.YieldToNextThread trick works well
enough for my needs, it could conceivably cause problems if you've
got multiple threads running with some intricate locking/syncing
going on - so YMMV...

Frank.
<http://developer.chaoticbox.com/>


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Are "protected" threads something possible in RB
Date: 27.11.07 07:37 (Tue, 27 Nov 2007 01:37:14 -0500)
From: lveillette
> This gets around the issues you mention regarding pre-emptve threading to
> some degree, by using a timer event to push audio. Youll need a different
> ancestor timer class that the MBS plugins provide - called
> "CarbonEventsTimerMBS". This operates similarish to the RB timer, but less
> prone to the crappy blocking issues you mention.
You are right, just one CarbonEventsTimerMBS does the trick...

Once more, MBSplugin saves the day :)

Louis

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>