• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSThread question - DO to make it sing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSThread question - DO to make it sing


  • Subject: Re: NSThread question - DO to make it sing
  • From: "Dennis C. De Mars" <email@hidden>
  • Date: Wed, 11 Jul 2001 09:57:27 -0700

on 7/11/01 8:47 AM, Candide Kemmler at email@hidden wrote:

> Le mardi 10 juillet 2001, ` 06:54, Miguel Morales a icrit :
>>
>> However, this would spawn a thread, but the main thread would wait for
>> the secondary thread to finish before continuing, and not give you any
>> of the functionality you want of the main thread plugging along. This
>> is where DO comes in. I will assume that there is a main object that
>> is running in a run loop, and that when the button gets pushed the
>> method -(void)button:(NSData *)data is called, and that there is
>> another method in the object that draws to the screen (also in the main
>> object) called -(oneway void)display:(bycopy NSData *)data.
>
> Great ! I've read the chapter on DO in "Object-Oriented Programming and
> the Objective-C Language" and I'm enthusiast about learning more on DO
> in OC. For a java-fan like me, it's like doing RMI and multi-threading
> at once ! However I find it a little odd to be forced to do rmi (or rpc,
> or whatever-you-name-it) just to do multi-threading.
>
> You said that the code snippet you give "would spawn a thread, but the
> main thread would wait for the secondary thread to finish before
> continuing" !!!!! That's the whole point of doing threads !
>
> Consider the following bit of java code:
>
> public void actionPerformed ( ActionEvent evt ) {
> if ( evt.getSource () == myButton ) {
> ( new Thread () {
> public void run () {
> renderMyImage ();
> }
> } ).start ();
> }
> }
>
> Isn't there a way as simple as this do achieve the same effect in
> Objective-C/Cocoa ?

If your "renderMyImage" routine used any Swing classes to do its rendering,
you'd have a problem with this code too, because Swing is not thread-safe
either; you are supposed to do all drawing in the main thread there too.

I think this is true of pretty much any GUI system of any complexity ever
devised -- you simply have to defer drawing to the main thread.

- Dennis D.


  • Follow-Ups:
    • Re: NSThread question - DO to make it sing
      • From: Candide Kemmler <email@hidden>
References: 
 >Re: NSThread question - DO to make it sing (From: Candide Kemmler <email@hidden>)

  • Prev by Date: Java Binaries?
  • Next by Date: Re: NSMovie
  • Previous by thread: Re: NSThread question - DO to make it sing
  • Next by thread: Re: NSThread question - DO to make it sing
  • Index(es):
    • Date
    • Thread