Multi-threading inside SketchUp
-
@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
-
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
-
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.
-
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.
-
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?
-
@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.
-
@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.) -
@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?
-
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
-
I need 64 bit support
-
-
@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.
-
@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.
-
@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 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.
Advertisement