confusing events

  • I have a class

    @interface MyClass : NSObject  <My_Protocol>
    @end

    @implementation MyClass
    -(void)main;
    {
    NSLog(@"%s start",__FUNCTION__);
    // do something mainly
    NSLog(@"%s end",__FUNCTION__);
    }

    -(oneway void)process
    {
    NSLog(@"%s",__FUNCTION__);
    // do some processing
    }
    @end

    MyClass lives in the main thread and gets process-messages via
    Distributed Objects (NSConnection) from a worker thread.

    Sometimes I see:

    -[MyClass main] start
    -[MyClass process]
    -[MyClass main] end

    That is:
    - some event starts the main method (actually it is [myClass
    performSelector: @selector(main) withObject: nil afterDelay: 0.0 ]),
    - then the execution is interrupted and switched to the process method,
    - then main resumes and runs until its end.

    All run in the same thread (I did log [NSThread currentThread]).
    I think this, i.e. the fact that the method triggered by an event
    does NOT run to its end, but gets interruped by another method (in
    the same thread), extremely confusing.
    Could someone point to some helpful documentation ?

    Kind regards,

    Gerriet.

    P.S. My current work-around is:

    -(oneway void)process
    {
    [self performSelector: @selector(realProcess) withObject: nil
    afterDelay: 0.0 ];
    }

    -(void)realProcess
    {
    NSLog(@"%s",__FUNCTION__);
    // do some processing
    }

    Now realProcess and main are no longer interleaved and all is fine.
  • On 9/10/07, Gerriet M. Denkmann <gerriet...> wrote:

    > All run in the same thread (I did log [NSThread currentThread]).
    > I think this, i.e. the fact that the method triggered by an event
    > does NOT run to its end, but gets interruped by another method (in
    > the same thread), extremely confusing.
    > Could someone point to some helpful documentation ?

    A thread wont jump to do something else unless the instructions in
    that thread make it do that other thing (ignoring signals, etc.).

    You didn't list what you do in main. As a guess I think you are
    triggering the running of the runloop in your "main" method. This
    allows the runloop to pickup an event from DO and result in the
    behavior you are reporting.

    As a side note I think using "main" as a method name could confuses
    others given main is normally only seen with the C entry function
    "main" and in the Java realm static main, etc. In fact I have seen GCC
    warn about use of main in some contexts.

    -Shawn
  • On 10 Sep 2007, at 17:50, Shawn Erickson wrote:

    > On 9/10/07, Gerriet M. Denkmann <gerriet...> wrote:
    >
    >> All run in the same thread (I did log [NSThread currentThread]).
    >> I think this, i.e. the fact that the method triggered by an event
    >> does NOT run to its end, but gets interruped by another method (in
    >> the same thread), extremely confusing.
    >> Could someone point to some helpful documentation ?
    >
    > A thread wont jump to do something else unless the instructions in
    > that thread make it do that other thing (ignoring signals, etc.).
    >
    > You didn't list what you do in main. As a guess I think you are
    > triggering the running of the runloop in your "main" method. This
    > allows the runloop to pickup an event from DO and result in the
    > behavior you are reporting.
    What "main" does: it first makes the worker thread stop its
    activities, then accesses a few NSProxies like:
    int age = [myProxy age];
    This obviously makes it relinquish control, so that the "process"-
    message from the other thread (which has been sitting in some queue)
    gets a chance to step in.

    >
    > As a side note I think using "main" as a method name could confuses
    > others given main is normally only seen with the C entry function
    > "main" and in the Java realm static main, etc. In fact I have seen GCC
    > warn about use of main in some contexts.

    Sorry about this. "main" is just a (rather badly chosen) name typed
    in Mail. The real method is named quite differently.

    Kind regards,

    Gerriet.
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today