A computer science question regarding the order in which object scripts are run.

I have a script manager with a list. The script manager has a “hash tree” function which looks for a specific entry in the list. Multiple other objects can access the script manager and tell it to insert data into the list. In what order does Unity process things? If “Cube” tells the script manager “put me in the list” script manager starts searching the list and finds where cube belongs so the list is always in order. But “Sphere” also wants in the list and is going to tell script manager in the same frame that he wants in the list as well so it’s going to call the same function to start searching for where Sphere goes on the list.

Is it possible for “Cube” to be added to the list while the script manager is still searching for “Sphere’s” place in the list? Both Cube and Sphere directly access the “script manager” and script by its object reference and access a function in that script called register. I.E. both Cube and Sphere call a search and add function. If Cube calls it first, is it possible for Cube to arrive at the “add me here” part of the function while Sphere is mid-way through searching the list?

Or, is it only possible for one function to be run at a time?

Within Unity you usually don’t face that kind of issue, because scripts are executed one after another. The order in which the scripts are executed is random, unless you are using the script execution order:

In the case that you are using multiple threads, just use the usual thread functionality:
https://www.google.com/search?q=c%23+threading

Thanks, that’s what I was trying to determine. I was just worried that both would call the same sorting function which subsequently modifies the list it is searching through and the list might be altered by one function call while the second function call is still searching, which would ruin the particular kind of search algorithm I’m using: http://railspikes.com/assets/2008/10/3/binary_search.png.

Thanks again, I just wasn’t sure that it really did one thing at a time.