Raised This Month: $51 Target: $400
 12% 

New API and Syntax


Post New Thread Reply   
 
Thread Tools Display Modes
kossolax
AlliedModders Donor
Join Date: Jan 2008
Location: Belgium
Old 06-26-2015 , 15:20   Re: New API and Syntax
Reply With Quote #521

Quote:
Originally Posted by Potato Uno View Post
Isn't pawn still single threaded? (On that note, how can SQL queries run on a second thread?)
Extention can run threaded code, then a callback is called into your plugin.
kossolax is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 06-27-2015 , 05:15   Re: New API and Syntax
Reply With Quote #522

So if you want a function to run on a separate thread, you would have to write that function as a C++ extension?
Potato Uno is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 06-27-2015 , 11:25   Re: New API and Syntax
Reply With Quote #523

I don't think you would want any threaded code (function) updating or accessing shared plugin memory (via natives) as it wouldn't be thread safe without you checking for such conditions.

Eg. You could update a char[] while a Sourcemod Plugin is calling StrEqual at the same time for a game event that just occurred in the main game thread.
Eg. You could have a loop condition on a global int that you change during the loop iteration.

These scenarios cause undesirable effects that are generally inconsistent in outcome and are really tough to debug. You need locking and all this other BS that I could rant on for ages about.

As kossolax said, for MySQL you want these queries to be run on worker threads so the main thread doesn't wait in a locked state for the SQL query to complete. The SQL query data doesn't need to be thread safe as when it completes, it's results are executed on the main thread via a callback.
__________________
Neuro Toxin is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 06-28-2015 , 00:54   Re: New API and Syntax
Reply With Quote #524

Hey bail, small question on the methodmaps.

I used Voided's source engine like methodmaps to handle entity stuff a little easier but when I tried using them with loops and other time-critical parts, they'd lag the hell out of the server CPU compared to simply using entities as ints...

Voided's methodmaps don't do anything except store the entity's reference ID.

why are they lagging the entity loops?

What I did exactly was loop through ALL entities, including validity checks, using a methodmap instance for an entity lags the server but a normal entity index loop with validity checks don't lag at all...

I'm assuming the speed issue is due to the backward compatibility with the older syntax?
__________________

Last edited by nergal; 06-28-2015 at 00:56.
nergal is offline
BAILOPAN
Join Date: Jan 2004
Old 06-29-2015 , 00:00   Re: New API and Syntax
Reply With Quote #525

Neuro Toxin is correct in that we want to make sure any sort of asynchronous API we provide does not have implicit shared state. That is pretty tricky if we have arbitrary concurrency in the language. Also note that (1) most SourceMod API is not thread-safe and (2) most Source Engine function calls are not thread-safe.

So the worker-model for things like MySQL works best for now.
__________________
egg
BAILOPAN is offline
BAILOPAN
Join Date: Jan 2004
Old 06-29-2015 , 00:02   Re: New API and Syntax
Reply With Quote #526

@nergal (Without having read your code or Voided's), that sounds very unlikely. But if it was the case, it was a bug somewhere. Methodmaps are just syntactic sugar and do not materially change the performance of code.
__________________
egg
BAILOPAN is offline
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 06-29-2015 , 23:56   Re: New API and Syntax
Reply With Quote #527

Code:
#include <sourcemod> #pragma semicolon 1 #pragma newdecls required public Plugin myinfo = {     name = "",     author = "",     description = "",     version = "" }; enum Struct {     ArrayList:arrTest, }; Struct g_ArrTest[Struct]; public void OnPluginStart() {     AddCommandListener(CommandListener_Callback, "test");     if (g_ArrTest[arrTest] == null) {         g_ArrTest[arrTest] = new ArrayList(1);     }     g_ArrTest[arrTest].Clear(); } public void OnPluginEnd() {     if (g_ArrTest[arrTest] != null) {         delete g_ArrTest[arrTest];         g_ArrTest[arrTest] = null;     } } public Action CommandListener_Callback(int client, const char [] command, int argc) {     if (!IsPlayerAlive(client))         return Plugin_Handled;     static int iTimes = 0;     iTimes++;     PrintToServer("0x%x", g_ArrTest[arrTest]);     if (g_ArrTest[arrTest] != null) {         g_ArrTest[arrTest].Push(iTimes);         for (int x = 0; x < g_ArrTest[arrTest].Length; x++) {             PrintToServer("iTimes is \"%d\"", g_ArrTest[arrTest].Get(x));         }         PrintToServer("======================End of loop======================\n");     }     return Plugin_Handled; }

handle 0x10000f
Error:
Code:
L 06/30/2015 - 11:32:54: [SM] Native "ArrayList.Get" reported: Invalid Handle 0 (error: 4)
L 06/30/2015 - 11:32:54: [SM] Displaying call stack trace for plugin "test.smx":
L 06/30/2015 - 11:32:54: [SM]   [0]  Line 51, test.sp::CommandListener_Callback()
Is it a bug ?
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
BAILOPAN
Join Date: Jan 2004
Old 06-30-2015 , 18:49   Re: New API and Syntax
Reply With Quote #528

Does it happen without using enum structs? I.e.,

Code:
const int Struct = 0; ArrayList g_ArrTest[1];
__________________
egg
BAILOPAN is offline
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 06-30-2015 , 20:50   Re: New API and Syntax
Reply With Quote #529

Quote:
Originally Posted by BAILOPAN View Post
Does it happen without using enum structs? I.e.,

Code:
const int Struct = 0; ArrayList g_ArrTest[1];
The same as enum struct

Edited:
And for sure I use the last official version fo SourceMod and MetaMod:Source
__________________
QQ:116268742

Last edited by K.K.Lv; 06-30-2015 at 20:53.
K.K.Lv is offline
Send a message via MSN to K.K.Lv
BAILOPAN
Join Date: Jan 2004
Old 06-30-2015 , 23:28   Re: New API and Syntax
Reply With Quote #530

@K.K.Lv - Can you file @ https://bugs.alliedmods.net/ ? Seems legit.
__________________
egg
BAILOPAN is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:09.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode