Do plugins run on a single thread?Solved
Hi just a quick question probably very stupid but I need to make sure. Is it possible for a hook to be called on a plugin at the same time and then potentially run the same line of code within that hook at the same time? like a race condition?
Thanks
Plugins run in the main thread generally. Unity has some coroutines you can use, but otherwise main thread that the server runs with. Hooks are called when the game triggers them, and any code that happens in that hook only happens during that time. You can call webrequests and run database requests, but those are handled in another thread and will not affect the outcome of that hook.
Ok just to clarefy so i fully understand. Say on player death is called at the exact same time(I know its almost impossible) will the hook finish running before the other hook is called for the second death?
The hook would be called twice, once for each death. The one would not wait for the other.
I dont think i explained it well so i just threw something together real quick. Say this was the hook for when a player died and they both died at the same time. Is it possible for count to = 1 or will it allways = 2
int count = 0;
        private bool OnHookCalled(){
            int newCount = count;
           someReallyCoolMethod();
            count = newCount + 1; 
        }​

 

The hooks would be called when the game calls them, so whenever the player dies. It would be 1 when it is first added to, so whichever hook was called a fraction faster.
Ah i got you. So there will allways be a hook that is called first. Thanks for your explaination. Very helpfull!
So how does it handle "re-entrancy" of data?
say for example a plugin  uses a trigger method to read a datafile.. & write datadile at end.
both calls read same data, but depending on which code path finshes first & execution path  ..
The  datafile may have inconsistent data written back, path A OR B as opposed to  path A AND B
From reading the anouncments they put out. They say the file IO is very slow so im guessing it runs on the main thread? and im guessing that means it would wait for the file to be closed before the next trigger would open the file. I might be wrong tho?
mrcameron999
From reading the anouncments they put out. They say the file IO is very slow so im guessing it runs on the main thread? and im guessing that means it would wait for the file to be closed before the next trigger would open the file. I might be wrong tho?

if that was the case it might spell big trouble for the hooks, they would all be queued up waiting for file I/O...
so you might get shot in the head and not die for 30 minutes........;-)

I was thinknig more along the lines of the file opening, getting data for hook 1, closing, opening for hook2, closing..
processing... hook 1 writes updated databack.. then hook 2 craps all over it...

Data is stored in memory, and you shouldn't really be writting to that file every split second.
Ahh ok. Now I have learnt! Thank you
Locked automatically