Amaury Forgeot d Arc <[email protected]> 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 <[email protected]>
<https://bugs.pypy.org/issue1465>
________________________________________
_______________________________________________
pypy-issue mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-issue

Reply via email to