[pypy-issue] [issue1465] cffi callback crashes in multithread environment

Amaury Forgeot d Arc tracker at bugs.pypy.org
Sun Apr 28 21:56:54 CEST 2013


Amaury Forgeot d Arc <amauryfa at gmail.com> added the comment:

A self-contained script below.
It does not crash when the thread was created from Python code
(with
    thread.start_new_thread(lib.another_thread, (ffi.NULL,))
)



from cffi import FFI
ffi = FFI()
ffi.cdef("""
void register_thread_callback(int (*func)());
""")
lib = ffi.verify("""
#include <stdio.h>
#include <pthread.h>

int (*global_thread_callback)();
void *another_thread(void *arg)
{
    printf("this is another thread\\n");
    global_thread_callback();
    return NULL;
}
void register_thread_callback(int (*func)())
{
    global_thread_callback = func;
    pthread_t tid;

    pthread_create(&tid, NULL, another_thread, NULL);
}
""")

@ffi.callback("int()")
def thread_callback():
    print 'thread call back OK'
    return 0
lib.register_thread_callback(thread_callback)
while True:
    pass

----------
nosy: +amaury

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1465>
________________________________________


More information about the pypy-issue mailing list