Thread within a class. are they 2 threads? - Linux

This is a discussion on Thread within a class. are they 2 threads? - Linux ; Hi, assume we have a class OrdinaryClass which does NOT extend the thread class or implement the runnable interface but embodies a separate thread InnerClass, i.e. class OrdinaryClass { --- --- set of instruction ---- thread InnerClass { /// } ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Thread within a class. are they 2 threads?

  1. Thread within a class. are they 2 threads?

    Hi,

    assume we have a class OrdinaryClass which does NOT extend the thread
    class or implement the runnable interface but embodies a separate
    thread InnerClass, i.e.

    class OrdinaryClass {
    ---
    --- set of instruction
    ----
    thread InnerClass
    {
    ///
    }
    ----
    } // end of ordinary class

    my question will InnerClass and the remaining OrdinaryClass code be
    considered as two separate threads which can run in parallel , say, in
    multiprocessors machine? why i am asking this question? well, I have
    just realised that if OrdinaryClass is a GUI code with embedded thread
    class : InnerClass which goes regularly on sleep mode for a long
    duration (as being hard coded), the GUI keeps responding IMMEDIATELY to
    any user interaction. i thought the Ordinary class process should be in
    sleep mode and not waked up until the long duration sepicified in the
    sleep argument elapses. However, the process seems responding
    immediately to any mouse click. any explanation please? does it mean,
    we have two separate threads despite not coding explictly so


    Thanks


  2. Re: Thread within a class. are they 2 threads?

    xu_feng_xu@yahoo.com wrote:
    > assume we have a class OrdinaryClass which does NOT extend the thread
    > class or implement the runnable interface but embodies a separate
    > thread InnerClass, i.e.


    One thing here already: the only information as to what language you are
    using is given by the fact that you posted to colds. Since the topic of
    that group is written in C and you are talking about classes there is
    nothing that can help you. Next time, please research where you are
    posting and also reread your posting considering whether all relevant
    information are present. Also, set a follow-up if you cross post, I set it
    to cpt now.

    Now, concerning the relation between threads and objects, in most cases
    there is none. Just as an object of class file is typically not a file but
    just a handle to manage a file, the same applies to class thread in
    typical application frameworks. If an object of class file is destroyed,
    it doesn't delete the file on disk and the same sometimes applies to
    objects of class thread, too (the case where a dtor forcefully terminates
    a thread isn't worth mentioning).

    That means that it only helps creating and managing a thread, but otherwise
    a point of control (which is what a thread is) and an object (i.e. some
    memory and associated functions) are different concepts that have nothing
    to do with each other.

    > class OrdinaryClass {
    > ---
    > --- set of instruction
    > ----
    > thread InnerClass
    > {
    > ///
    > }
    > ----
    > } // end of ordinary class
    >
    > my question will InnerClass and the remaining OrdinaryClass code be
    > considered as two separate threads which can run in parallel , say, in
    > multiprocessors machine?


    Impossible to answer without background info. In C++ a nested class is just
    syntactic sugar and since it deals with objects and not classes they are
    separate anyway so the answer would be yes. Any thread there can call
    functions of any class and I find it hard to imagine a general-purpose
    language where that is not the case.

    > why i am asking this question? well, I have just realised that if
    > OrdinaryClass is a GUI code with embedded thread class : InnerClass
    > which goes regularly on sleep mode for a long
    > duration (as being hard coded), the GUI keeps responding IMMEDIATELY to
    > any user interaction. i thought the Ordinary class process should be in
    > sleep mode and not waked up until the long duration sepicified in the
    > sleep argument elapses. However, the process seems responding
    > immediately to any mouse click. any explanation please? does it mean,
    > we have two separate threads despite not coding explictly so


    Again, impossible to answer for lack of information.

    Uli


+ Reply to Thread