sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Multi-threading inside SketchUp

    Scheduled Pinned Locked Moved Developers' Forum
    17 Posts 10 Posters 5.7k Views 10 Watching
    Loading More Posts
    • 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.
    • T Offline
      tomasz
      last edited by

      @bcbas said:

      So, what I'm wondering is why this happens? What are the multi-threading rules and concepts inside SketchUp?

      There are no publicly known rules. I am not sure if even Scott from Google knows what is going on in the background.

      I have been using threads to open a Kerkythea, but it just has caused that SU has frozen after some time. When KT has been closed SU has been back on track.

      Tomasz

      Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

      1 Reply Last reply Reply Quote 0
      • Tyler MillerT Offline
        Tyler Miller
        last edited by

        Hi bcbas -

        I've asked around a bit here and no one on the SketchUp dev team has attempted to use Ruby threads in our scripts (Sandbox, Dynamic Components, etc.). There are no "special" rules dictated by SketchUp, but SketchUp does own the main event loop. This could present some issues as there is the question of what happens to the thread when the script is "done" executing. From your description, the child thread sounds like it is being abandon, rather than killed, once the script is done executing. That could be bad on several levels.

        I wish we could be of more help. I think you're just going to have to experiment with it.

        -Tyler

        1 Reply Last reply Reply Quote 0
        • tbdT Offline
          tbd
          last edited by

          my advice: don't do it, unless you want to spend lots of nights searching the reasons of crashes that have no explanations.

          also do not mix native threading with ruby threading - they don't like each other much.

          SketchUp Ruby Consultant | Podium 1.x developer
          http://plugins.ro

          1 Reply Last reply Reply Quote 0
          • J Offline
            jhauswirth
            last edited by

            I have tried threads from a Ruby script in SU and found that the thread only gets executed when other Ruby commands are executed. Create your thread and then run some other Ruby commands (like a loop that prints out stuff) and you'll see that your thread will actually get executed. I don't think Ruby is actually creating a real thread, its just handling the time slices itself- which means you have to be giving the Ruby interpreter CPU time to do its business.

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              So after creating the threads, you have to start a loop that runs until your threads complete? And that means you can't do anything else in SU while the threads execute?

              Thomas Thomassen β€” SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • J Offline
                jhauswirth
                last edited by

                @thomthom said:

                So after creating the threads, you have to start a loop that runs until your threads complete? And that means you can't do anything else in SU while the threads execute?

                That's what I found, but this solution wouldn't work for me because I needed the thread to always run.

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  @thomthom said:

                  So after creating the threads, you have to start a loop that runs until your threads complete?

                  NO... use Thread.join instead of a loop.
                  ` th1 = Thread.new {

                  code

                  }
                  th1.join`
                  Suggest always have an exit condition inside thread. Not like example in first post (ie, it's an endless loop.)

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • M Offline
                    MartinRinehart
                    last edited by

                    @dan rathbun said:

                    ... Suggest ...

                    Dan,

                    I've played a lot with threads in SketchUp Ruby and have zero useful results. Could you post a small example that actually works?

                    Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                    1 Reply Last reply Reply Quote 0
                    • C Offline
                      cjthompson
                      last edited by

                      This gets the best results for me so far. It's really slow, but it seems to be executing on a regular basis.

                      
                      def testThread(times)
                      	timer = UI.start_timer(0,true){Sketchup.active_model.entities}
                      	thread = Thread.new{(0...times).each{|num| addBox};UI.stop_timer(timer)}
                      end
                      
                      def addBox
                      	group = Sketchup.active_model.entities.add_group
                      	face = group.entities.add_face([0,0,0],[1,0,0],[1,1,0],[0,1,0])
                      	face.pushpull(-1)
                      	group.transformation = Geom;;Transformation.new([rand(500),rand(500),rand(500)])
                      end
                      
                      
                      1 Reply Last reply Reply Quote 0
                      • A Offline
                        Aidus
                        last edited by

                        I need 64 bit support 😞

                        CPU: Intel Core i7 Extreme Edition 965
                        RAM: OCZ Gold DDR3 1600MHz 12Gb
                        Video: Asus Radeon HD4870 X2 2Gb
                        Mobo: Asus P6T Deluxe 1366 Intel X58

                        1 Reply Last reply Reply Quote 0
                        • thomthomT Offline
                          thomthom
                          last edited by

                          @aidus said:

                          I need 64 bit support 😞

                          For what?

                          Thomas Thomassen β€” SketchUp Monkey & Coding addict
                          List of my plugins and link to the CookieWare fund

                          1 Reply Last reply Reply Quote 0
                          • Dan RathbunD Offline
                            Dan Rathbun
                            last edited by

                            @aidus said:

                            I need 64 bit support 😞

                            This topic is about using Ruby "Green" threads, not native OS threads (which can run on several CPU cores.)

                            Ruby ver 2.0 "may" have native thread support, but current estimates of the work to be done, has 2.0 needing 17 years more work.

                            I'm not here much anymore.

                            1 Reply Last reply Reply Quote 0
                            • C Offline
                              cjthompson
                              last edited by

                              @dan rathbun said:

                              @aidus said:

                              I need 64 bit support 😞

                              This topic is about using Ruby "Green" threads, not native OS threads (which can run on several CPU cores.)

                              Ruby ver 2.0 "may" have native thread support, but current estimates of the work to be done, has 2.0 needing 17 years more work.

                              I thought 1.9 had basic support for native threads, but Sketchup can't connect to its hooks.

                              1 Reply Last reply Reply Quote 0
                              • Dan RathbunD Offline
                                Dan Rathbun
                                last edited by

                                @cjthompson said:

                                I thought 1.9 had basic support for native threads, but Sketchup can't connect to its hooks.

                                Might be.. (I'd like to know for sure if you can post a link.)

                                However Sketchup cannot currently load the 1.9.x interpreter DLL (... I've tried, and get an "entry point not found error." There seems to be some kind of difference between the 1.8.x and the 1.9.x DLLS, which I'd also like to know why this is. )

                                Also, "basic support" I read as "beta" (and likely error prone.)

                                I'm not here much anymore.

                                1 Reply Last reply Reply Quote 0
                                • A Offline
                                  Aidus
                                  last edited by

                                  I'm working with very large textures and I think su offten crashes because of that reason. It just can't work with very large files. You can operate inside sketchup but forget the export. Well that's just my guess. At home I have x64 bit os and there are no such problems - not so offten.

                                  CPU: Intel Core i7 Extreme Edition 965
                                  RAM: OCZ Gold DDR3 1600MHz 12Gb
                                  Video: Asus Radeon HD4870 X2 2Gb
                                  Mobo: Asus P6T Deluxe 1366 Intel X58

                                  1 Reply Last reply Reply Quote 0
                                  • 1 / 1
                                  • First post
                                    Last post
                                  Buy SketchPlus
                                  Buy SUbD
                                  Buy WrapR
                                  Buy eBook
                                  Buy Modelur
                                  Buy Vertex Tools
                                  Buy SketchCuisine
                                  Buy FormFonts

                                  Advertisement