anyone of you having experience with "create thread" option that is showing up in custom actions?
if yes, i would like to know when it makes sens to enable this option in general? does it make sens to enable it for all actions that are quite complex and run very often in the background? or does it always make sens if its possible? could it cause any bugs or other problems?
"create thread" translates to "create a new trigger, create global variables for parameters and return value, execute trigger".
So no, it is not recommended do use this option, unless you really need to.
It does not really cause bugs, but it increases the execution time and the amount of created code by a significant amount, if you just check it for every action.
€ to clarify: This is NOT significant, if checked for 1 single action. If you need the action to run in it's own thread, hell, do it!.
However, you should not do this for every action you can find, because it has no advantages if you don't absolutely need the thread.
In the past I have used it. And main reason for doing so is when I had very long function which was calling several other functions and some looping was going on.
I was getting a "Thread is too long" error. Which is problematic because when you hit that error the trigger stops running. So I set some of the subfunctions to Create Threads. So thats where you'll need it. When using it though make sure to watch out for getting a "Too many threads" error.
Unfortunately since most of the length of the function I was using was because it kept looping back on itself to try and find all the possible movement routes this just got me a "Too many threads" error. Eventually I had to duplicate the function and make them call each other, and make it so only one of them Created a New Thread. Therefore every other call would be separated instead of every call.
If MyCustomAction() has a Wait or some loop that takes time to do, then it halts the execution of the entire trigger. If it has "Create Thread", it will not stop the trigger, it will become it's own, independent thread and run parallel to other stuff (like triggers do).
The danger is that too many threads will slow down the whole thing, and there is some limit (not idea what it is :P)
I'll attach a test map of mine that taught me what Create Thread is about. First run it without changing anything (and do what it says) and then run it again with "Create Thread" unchecked for the Teleport action, you'll see the difference.
Easy stuff.
But see how the way of execution changes when you enable/disable the Create Thread option of MyCustomAction.
If it's disabled, then all 10 executions of MyCustomAction are executed after each other. That means the entire trigger executes in 50-100 seconds.
If it's enabled, then all 10 executions of MyCustomAction are executed at the same time. That means the entire trigger executes in 5-10 seconds.
The Create Thread option enabled eats a little bit of memory, and it most probably also is a tad bit slower to call than without.
It really isn't about execution time, amount of code or anything else. Use Create Thread only, if it creates the desired effect of not stopping the trigger calling it.
hey guys,
anyone of you having experience with "create thread" option that is showing up in custom actions? if yes, i would like to know when it makes sens to enable this option in general? does it make sens to enable it for all actions that are quite complex and run very often in the background? or does it always make sens if its possible? could it cause any bugs or other problems?
"create thread" translates to "create a new trigger, create global variables for parameters and return value, execute trigger".
So no, it is not recommended do use this option, unless you really need to.
It does not really cause bugs, but it increases the execution time and the amount of created code by a significant amount, if you just check it for every action.
€ to clarify: This is NOT significant, if checked for 1 single action. If you need the action to run in it's own thread, hell, do it!.
However, you should not do this for every action you can find, because it has no advantages if you don't absolutely need the thread.
so, when does it make sens to use it and why?
if it increases execution time and code length it seems quite pointless to me.
check the API on this site it mentions some stuff about it.
In the past I have used it. And main reason for doing so is when I had very long function which was calling several other functions and some looping was going on.
I was getting a "Thread is too long" error. Which is problematic because when you hit that error the trigger stops running. So I set some of the subfunctions to Create Threads. So thats where you'll need it. When using it though make sure to watch out for getting a "Too many threads" error.
Unfortunately since most of the length of the function I was using was because it kept looping back on itself to try and find all the possible movement routes this just got me a "Too many threads" error. Eventually I had to duplicate the function and make them call each other, and make it so only one of them Created a New Thread. Therefore every other call would be separated instead of every call.
Let's say you have a trigger with some stuff and a custom action in there somewhere:
If MyCustomAction() has a Wait or some loop that takes time to do, then it halts the execution of the entire trigger. If it has "Create Thread", it will not stop the trigger, it will become it's own, independent thread and run parallel to other stuff (like triggers do).
The danger is that too many threads will slow down the whole thing, and there is some limit (not idea what it is :P)
I'll attach a test map of mine that taught me what Create Thread is about. First run it without changing anything (and do what it says) and then run it again with "Create Thread" unchecked for the Teleport action, you'll see the difference.
It is useful if you want your Action to not stop the execution of the mother thread.
Let's say you want a trigger that creates 10 marines in a time period between 5 and 10 seconds:
Easy stuff.
But see how the way of execution changes when you enable/disable the Create Thread option of MyCustomAction.
If it's disabled, then all 10 executions of MyCustomAction are executed after each other. That means the entire trigger executes in 50-100 seconds.
If it's enabled, then all 10 executions of MyCustomAction are executed at the same time. That means the entire trigger executes in 5-10 seconds.
The Create Thread option enabled eats a little bit of memory, and it most probably also is a tad bit slower to call than without.
It really isn't about execution time, amount of code or anything else. Use Create Thread only, if it creates the desired effect of not stopping the trigger calling it.
ah ok, so it really just makes sens if i want to do some things parallel.
cause i had other things in mind when hearing "thread", like multicore support and such things.