Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Behind the Scenes
  3. Wiki Discussion
  4. Discussion about "Threads, Events and QObjects" article
Forum Updated to NodeBB v4.3 + New Features

Discussion about "Threads, Events and QObjects" article

Scheduled Pinned Locked Moved Wiki Discussion
59 Posts 17 Posters 48.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dangelog
    wrote on last edited by
    #5

    [quote author="Gerolf Reinwardt" date="1292356379"]bq. What do you mean? Right now there’s a simple example by an hypotetic recursion into a slot. Do you think I should stressing on it even more?

    I meant that it can not only fore recursion, it can also fore a stutdown or delete of an object, that you currently work on. Think of deleteLater, which is executed by the event loop. This can happen when you call @QApplication::processEvents@. And then, perhaps, an object, where yiou think it exists, is away. And I saw suxgh tghings, especially not recursions but unexpected object deletion which result in a crash. And then all you get is:
    bq. It crashes, I don't know why, but here the memory is freed.....

    And you are the happy person to find the bug, they introduced by spinning the event loop out of scope...

    So I would make a bigger note with many exclamation marks and warnings... :-))[/quote]

    Ok, I got it now :-)

    Well, I've integrated your suggestions here and there. Give it a read if you want to :)

    [quote author="chetankjain" date="1292393650"]moving this to Wiki forum, thats the right place to initiate discussions on wiki articles[/quote]

    Ops! You're right, sorry about that.

    Software Engineer
    KDAB (UK) Ltd., a KDAB Group company

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #6

      Hi,
      thanks again, the article is really good, and I think, the pitfalls are clearer now. So looking fporward to your next article :-))

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • W Offline
        W Offline
        Wolf P.
        wrote on last edited by
        #7

        bq. how to start, stop, join a thread under (at least) one major operating system;

        Is joining threads such a common pattern?
        I've always imagined threads as autonomous agents. This I was able to produce programmatically and at some point they were finished and forgotten. Whether or not the program code orphaned never seemed to matter to me.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #8

          Joining threads is common, if you put parts of a bigger thing to threads to do that in paralell and want to wait for all results being finished. I know, it can also be done with QtConcurrent but some programs are older than QtConcurrent :-))

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dangelog
            wrote on last edited by
            #9

            [quote author="Wolf P." date="1292845577"]bq. how to start, stop, join a thread under (at least) one major operating system;

            Is joining threads such a common pattern?
            I've always imagined threads as autonomous agents. This I was able to produce programmatically and at some point they were finished and forgotten. Whether or not the program code orphaned never seemed to matter to me.[/quote]

            It's a pattern, that's all. For instance, a possible use case is telling a worker thread to finish, then actually wait for it to end (by joining it), then deallocate some resources used by it.

            Software Engineer
            KDAB (UK) Ltd., a KDAB Group company

            1 Reply Last reply
            0
            • W Offline
              W Offline
              Wolf P.
              wrote on last edited by
              #10

              Gerolf, I see. The somewhat outdated framework I worked with, provided only the forking.
              Do you know a good real-world example?

              Peppe, as I see, to join means simply to wait?

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #11

                Join means wait for finish, yes.
                I have some in my work, but they are not open source :-)
                removing objects, which are are internally multithreadded for example. You have to close all threads before removing the object.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dangelog
                  wrote on last edited by
                  #12

                  [quote author="Wolf P." date="1292847084"]Gerolf, I see. The somewhat outdated framework I worked with, provided only the forking.
                  Do you know a good real-world example?

                  Peppe, as I see, to join means simply to wait?[/quote]

                  I was pretty sure it was standard lexicon when it comes to threading: it means "block the calling thread until the target thread terminates"; and yes, it's what QThread::wait() does. See for instance:
                  http://www.kernel.org/doc/man-pages/online/pages/man3/pthread_join.3.html
                  http://download.oracle.com/javase/6/docs/api/java/lang/Thread.html#join()
                  http://perldoc.perl.org/threads.html#DESCRIPTION

                  Now that you're telling me, perhaps should I change that term?

                  Software Engineer
                  KDAB (UK) Ltd., a KDAB Group company

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #13

                    I must admit, I did not read the wiki article, but have some experience with QThread. The term "join a thread" was unknown to me, so although this might be a common term in threading in general, it seems it is not used in Qt world.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      giesbert
                      wrote on last edited by
                      #14

                      It is common in Boost threadding for example, that's where I know it from. If it is a general term... ???

                      Nokia Certified Qt Specialist.
                      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        dangelog
                        wrote on last edited by
                        #15

                        I can put a footnote and/or a link there, just in case. The point is that you should know what QThread::wait() is for. What do you think?

                        Software Engineer
                        KDAB (UK) Ltd., a KDAB Group company

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          goetz
                          wrote on last edited by
                          #16

                          Knowledge about QThread::wait() is definitely needed.

                          maybe this wording is a bit more clear:

                          "how to start, stop, wait for a thread (aka join a thread in boost and others) under (at least) one major operating system"

                          http://www.catb.org/~esr/faqs/smart-questions.html

                          1 Reply Last reply
                          0
                          • W Offline
                            W Offline
                            Wolf P.
                            wrote on last edited by
                            #17

                            [quote author="Volker" date="1292850647"] "how to start, stop, wait for a thread [/quote]
                            This sounds very familiar to me (FYI: Win32/VCL).

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              dangelog
                              wrote on last edited by
                              #18

                              Ok, I changed the sentence to
                              [quote]
                              how to start and stop a thread, and wait for it to finish, under (at least) one major operating system;
                              [/quote]

                              Thank you all for your feedback :)

                              Software Engineer
                              KDAB (UK) Ltd., a KDAB Group company

                              1 Reply Last reply
                              0
                              • W Offline
                                W Offline
                                Wolf P.
                                wrote on last edited by
                                #19

                                Another choice of terminology has me confused: reentrant. Thread-safe I understood, but the definition of reentrancy seemed not clearly demarcated from it. Maybe a slight reworking of the text could help for a better understanding of the difference.

                                1 Reply Last reply
                                0
                                • W Offline
                                  W Offline
                                  Wolf P.
                                  wrote on last edited by
                                  #20

                                  Sorry for this naive comment. Finally I found that this is Qt terminology: http://doc.qt.nokia.com/latest/threads-reentrancy.html

                                  1 Reply Last reply
                                  0
                                  • F Offline
                                    F Offline
                                    Franzk
                                    wrote on last edited by
                                    #21

                                    It is not just Qt terminology. It's general programming terminology and something everyone who does at least the slightest bit of multi-threading should know about.

                                    http://en.wikipedia.org/wiki/Reentrant_(subroutine)
                                    http://en.wikipedia.org/wiki/Thread_safety

                                    "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                                    http://www.catb.org/~esr/faqs/smart-questions.html

                                    1 Reply Last reply
                                    0
                                    • W Offline
                                      W Offline
                                      Wolf P.
                                      wrote on last edited by
                                      #22

                                      [quote author="Franzk" date="1292858262"]...and something everyone who does at least the slightest bit of multi-threading should know about.[/quote] thx for the WP references :)

                                      BTW: I did some multithreaded coding without problems, and without thinking about reentrance.

                                      1 Reply Last reply
                                      0
                                      • D Offline
                                        D Offline
                                        dangelog
                                        wrote on last edited by
                                        #23

                                        To be honest, the little problem is that there might be some confusion due to literature and/or other toolkits. That's why I specified that in the article I follow the Qt conventions; anyway, I added a link to http://doc.qt.nokia.com/latest/threads-reentrancy.html, just to make it even more clear :-)

                                        Software Engineer
                                        KDAB (UK) Ltd., a KDAB Group company

                                        1 Reply Last reply
                                        0
                                        • F Offline
                                          F Offline
                                          Franzk
                                          wrote on last edited by
                                          #24

                                          It's good. The basics are the same across libraries though (bad library if it diverges...).

                                          "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                                          http://www.catb.org/~esr/faqs/smart-questions.html

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved