我有以下代码:
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]当我终于在gdb中运行luajit时,这就是冻结时的回溯:
(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 ()所以在我看来,有东西阻塞了互斥体,这有点奇怪,因为,虽然有两个线程在运行,但只有一个线程甚至触及到了物理学家(第二个线程甚至没有ffi.load "physfs")。
我能做些什么?
发布于 2015-02-13 22:03:27
我仍然不知道到底是怎么回事,但是当我试图进一步调试gdb中的互斥体时,LD_PRELOAD libpthread.so到gdb进程,突然起作用了。
然后我试着把它预装到没有gdb的luajit上,也能工作。
然后,我进一步研究了physfs和lualane(这是我用于线程处理的p线程ffi包装器),以找出它们都试图加载libp线程(如果还没有加载),但是来自C和lualane的物理学家使用ffi,而ffi不知怎么没有看到由physfs加载的文件,这个过程最后加载了两个库副本。
因此,修复方法是在ffi.load"pthread"之前解释一个ffi.load"physfs",因为虽然泳道看不到由物理学家加载的版本,但物理学家只是对我们加载的版本感到满意,并且不再尝试加载它,而luajit则忽略了通道所做的进一步加载尝试。
https://stackoverflow.com/questions/28486394
复制相似问题