DarkLink Posted December 17, 2011 Share Posted December 17, 2011 Hi there guys, I have one question in mind . Does server scripts manage concurrency ? Example, on server script there is a var like x = 2 I mean, two client at the same time try to acess a function on a server side script and both try to decrement that var, it would like x = 0 if server manage concurrency like a locks on java. But if server doesnt support concurrency on blocks, and they try to decrement x at the same time, it will appear x = 1, caused by a dirty read. My question is, how this works on MTA ? I am out of MTA for a few months, and when we came back to Lua coming from Java its kinda weird x) Thanks alot in advance. Link to comment
BinSlayer1 Posted December 17, 2011 Share Posted December 17, 2011 I am not sure I got you right.. But if 2 clients use event triggering to serverside to handle decrementation of a variable then it will happen twice (because 2 clients do it) To avoid this, you'll need to use dictionary tables Link to comment
DarkLink Posted December 17, 2011 Author Share Posted December 17, 2011 Hmm I see, thanks for your reply. Thats fine, but look if two clients do the same operation (trigger the same event to serverside), what will happen if that is a critic zone ? that I want only one client executing at same time ? do you understand? Thats why we use synchronized on java, I am asking how Lua on mta handle this.. Thanks in advance guys Link to comment
Siml0x Posted December 18, 2011 Share Posted December 18, 2011 I'm not quite sure if I understood you correctly, but I think you are talking about problems with a multithreaded environment. As far as I know MTA handles the scripting part in one single thread. Therefore it would be (for the server): Global Var x = 2 Client A triggers the event. Client B triggers the event. Server Recognizes the Event of Client A Function is executed x is now 1 Server Recognizes the Event of Client B Function is executed x is now 0 Link to comment
DarkLink Posted December 18, 2011 Author Share Posted December 18, 2011 Yes you are close dude, thanks for your reply. But still didnt got fully clarified.. clients are individual threads right? So how do I make a piece of code only executed by one client at a time ? Do u understand ? LOCK the method/function, synchronized methods on java. Thanks. Link to comment
qaisjp Posted December 18, 2011 Share Posted December 18, 2011 Then use a "ready" variable check. Link to comment
BinSlayer1 Posted December 18, 2011 Share Posted December 18, 2011 use getTickCount() to see how fast a server function gets called.. if it's less than a second than the previous call then don't execute it Link to comment
DarkLink Posted December 18, 2011 Author Share Posted December 18, 2011 okay guys thanks alot for the help Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now