Open Wend4r opened 1 year ago
sub_320880(
&dword_76F380,
"sv_parallel_send",
"0",
0x80000,
"Pack and send snapshots in parallel for smoother server tick rate at the expense of spending more CPU.",
sub_1AF5F0);
sv_parallel_send
description also talks about unloading the main game thread
Also I remember that IMemAlloc::Alloc
, IMemAlloc::Realloc
and IMemAlloc::Free
can be called from different threads that can hooks SourceMod DHooks. I had to rewrite everything to SourceMod C++ Extension ðŸ˜
There is no thread safety model for SourcePawn data structures, and it'd be very difficult to define and implement one efficiently. And I'm opposed to a global interpreter lock, which defeats the point of threading. So really the only path forward is an isolation model, where separate threads do not share any resources except those that can be sent over pipes. Think something like Web Workers.
Even if we build that out, SourceMod is completely thread unsafe. Every single native would have to be audited, and the set of natives available would have to be restricted off the main thread. Otherwise it'd be a free-for-all and we'd get bug reports every day about how random thing X crashes 10% of the time.
tl;dr: a "proper" solution is not coming anytime soon. Instead, I think spot-fixes are needed for safety here. Anywhere a SourceHook callback could be called off the main thread, we should check and bypass interactions with main-thread plugins (and use mutexes if main thread data structures are at risk).
Your solution of using an extension or MM:S plugin is the right way, IMO.
Another case with asynchronous SDKHook_SetTransmit
Function | |
---|---|
0 | libc-2.31.so + 0x14dd90 |
1 | sourcepawn.jit.x86.so!sp::ScriptedInvoker::Invoke(int*) + 0x1a7 |
2 | sourcepawn.jit.x86.so!sp::ScriptedInvoker::Execute(int*) + 0x5f |
3 | sdkhooks.ext.2.csgo.so!SDKHooks::Call(CBaseEntity*, SDKHookType, CBaseEntity*) + 0x104 |
4 | sdkhooks.ext.2.csgo.so!SDKHooks::Hook_SetTransmit(CCheckTransmitInfo*, bool) + 0x55 |
5 | sdkhooks.ext.2.csgo.so!__SourceHook_MFHCls_SetTransmit::CMyDelegateImpl::Call(CCheckTransmitInfo*, bool) + 0x2d |
6 | sdkhooks.ext.2.csgo.so!__SourceHook_MFHCls_SetTransmit::Func(CCheckTransmitInfo*, bool) + 0x115 |
7 | server.so + 0x6d66c3 |
8 | engine.so + 0x1cc4a3 |
9 | engine.so + 0x1d4aba |
10 | engine.so + 0x1d4d19 |
11 | engine.so + 0x1d56bc |
12 | engine.so + 0x1d4db5 |
13 | engine.so + 0x1d4df1 |
14 | engine.so + 0x1d4e77 |
15 | libvstdlib.so + 0x1a679 |
16 | libtier0.so!CThread::ThreadProc(void*) + 0x97 |
17 | libpthread-2.31.so!start_thread [pthread_create.c:477 + 0x3] |
18 | libc-2.31.so!__clone + 0x66 |
19 | 0xc68ffb40 |
Reporting stacks is not helping anything. We've always known SP doesn't support running concurrently.
This is an sdkhooks bug not SP.
Hello, I would like to see support in SourcePawn for executing JIT OP-Code in several threads at the same time.
For example, when using![image](https://user-images.githubusercontent.com/47463683/183238235-0e24b91a-e16d-4b8b-a62c-99be0d8a5d10.png)
sv_parallel_send <numthreads>
that executesSetTransmit
in different threads (and in SourceMod), server does crashesI also need my upcoming PR to SourceMod with
async
(to make huge hierarchical miscalculations with the Navigation Meshes of the map without loading the main game thread (tick delays in milliseconds/aka server var) :P)