Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
luajit/physicsfs互斥锁死锁_Lua_Pthreads_Mutex_Deadlock_Luajit - Fatal编程技术网

luajit/physicsfs互斥锁死锁

luajit/physicsfs互斥锁死锁,lua,pthreads,mutex,deadlock,luajit,Lua,Pthreads,Mutex,Deadlock,Luajit,我有以下代码: local M=ffi.load "physfs" ffi.cdef [[ //basically the preprocessed content of physfs.h, see http://icculus.org/physfs/docs/html/physfs_8h.html ]] M.PHYSFS_init(arg[0]) M.PHYSFS_setSaneConfig("a","b","zip",0,0) function file2str(path) local

我有以下代码:

local M=ffi.load "physfs"
ffi.cdef [[ //basically the preprocessed content of physfs.h, see http://icculus.org/physfs/docs/html/physfs_8h.html ]]
M.PHYSFS_init(arg[0])
M.PHYSFS_setSaneConfig("a","b","zip",0,0)

function file2str(path)
  local cpath=ffi.cast("const char *",path)
  print(1) --debug
  if M.PHYSFS_exists(cpath)==0 then return nil,"file not found" end
  print(2) --debug
  -- some more magic
end
assert(file2str("someFile.txt"))
调用时,我期望调试输出1和2,或者至少断言触发,但我只得到:

1
["endless" (i pressed ^C after about a minute) freeze]
当我最终让luajit在gdb中运行时,这是冻结时的回溯:

(gdb) bt
#0  0x00007ffff37a5c40 in __pause_nocancel ()
    at ../sysdeps/unix/syscall-template.S:81
#1  0x00007ffff379bce6 in __pthread_mutex_lock_full (mutex=0x68cbf0)
    at ../nptl/pthread_mutex_lock.c:354
#2  0x00007ffff606951f in __PHYSFS_platformGrabMutex (mutex=0x68cbf0)
    at /home/kyra/YDist/src/physfs-2.0.3/platform/unix.c:403
#3  0x00007ffff606410d in PHYSFS_getWriteDir ()
    at /home/kyra/YDist/src/physfs-2.0.3/physfs.c:913
#4  0x000000000045482b in ?? ()
#5  0x000000000043a829 in ?? ()
#6  0x000000000043af17 in ?? ()
#7  0x00000000004526a6 in ?? ()
#8  0x0000000000446fb0 in lua_pcall ()
#9  0x00000000004047dc in _start ()
所以在我看来,似乎有什么东西在阻止互斥,这有点奇怪,因为虽然有两个线程在运行,但只有一个线程甚至接触到physfs(第二个线程甚至不
ffi.load“physfs”


我可以/应该做什么?

我仍然不知道到底发生了什么,但是在尝试进一步调试gdb中的互斥时,我
LD_PRELOAD
ed
libpthread。因此,
加载到gdb进程,突然它起了作用

然后我试着在没有gdb的情况下将其预加载到luajit,同样有效

然后我进一步深入研究了physfs和lualanes(这是我用于线程的pthread ffi包装器),发现如果还没有加载libpthread,它们都会尝试加载libpthread,但是使用ffi的C和lualanes的physfs却看不到physfs加载的那个,并且进程最终加载了库的两个副本

因此,修复方法是在
ffi.load“physfs”
之前明确地执行
ffi.load“pthread”
,因为虽然lanes看不到physfs加载的版本,但physfs对我们加载的版本很满意,并且不会再次尝试加载,而luajit ffi忽略了lanes进一步的加载尝试