Open GWRon opened 5 years ago
I tried to wrap the TTypeID.ForObject
call (so avoids potentially inserting into the map "simultaneously") ...
?threaded
LockMutex(reflectionMutex)
?
Local typeId:TTypeId = TTypeId.ForObject(args[i])
?threaded
UnLockMutex(reflectionMutex)
?
But this still lead to an segfault (in a different part):
#0 bbExThrow (p=0x7fffe32c65d0) at /BlitzMaxNG/mod/brl.mod/blitz.mod/blitz_ex.c:138
#1 0x00000000005c5dcc in brl_blitz_NullObjectError ()
at /BlitzMaxNG/mod/brl.mod/blitz.mod/.bmx/blitz.bmx.debug.linux.x64.c:555
#2 0x00000000005c6e40 in bbNullObjectTest (o=0x8ad178 <bbNullObject>)
at /BlitzMaxNG/mod/brl.mod/blitz.mod/blitz_object.c:231
#3 0x00000000004a5ef2 in _brl_reflection_TTypeId_FindMethod_S (o=0x7ffff0223d00, bbt_name=0x7fffe32d3860)
Think the brl.mod/reflection.mod is not threadsafe yet.
Are you using the reflection module from master or the brl_reflect branch? Either way, a lot of stuff in both of them currently isn't thread safe. I'm been planning to fix this eventually, but we should get a decision (from @woollybah?) on the topic of libffi: are we okay to use it in BlitzMax-NG from now on (it might restrict the platforms NG can run on)? If so, I'd like him to commit libffi to the brl_reflect branch (as mentioned before in bmx-ng/bcc/issues/413), since I had trouble getting it to build correctly. I'll then continue working on the reflection module.
I am using the "master" branch.
So it seems for now (while developing the threaded AI) I need to add some more mutexes.
Since yesterday I am trying to get my AI scripts (based on Lua) to work in extra threads.
So each AI has a "TLuaEngine"-object which does all the Lua stuff. Now I create a thread for each AI in which
Update()
(defined in BlitzMax) is constantly called (for now ;-)). ThisUpdate()
calls a method of the lua engineCallLuaFunction(name, params)
.Removing the
CallLuaFunction()
... works as expected. Adding in theCallLuaFunction()
... segfault Wrapping the CallLuaFunction into aLockMutex() ... UnlockMutex()
... worksThe segfault has this backtrace:
The corresponding code is: https://github.com/GWRon/Dig/blob/master/base.util.luaengine.bmx
Sample code:
ai.lua:
Is this a reflection issue or does the Lua binding trash some stuff?