ming <[email protected]> added the comment:

I was using cffi callback to call my python function from my c library; it 
works 
fine when they are all in one thread, but it crashes when my c library create a 
new thread and do the "callback" in new thread.

The error sometime is "Segmentfalut 11", sometimes is "bus error"

Pypy version: pypy-2.0-beta2

CPython works fine in my test program.

You can see the code crashes Pypy in the attached file. The C code is like this:

#include <stdio.h>
int (*global_thread_callback)();

#include <pthread.h>


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);
}


The Python code is like this:

from cffi import FFI
ffi = FFI()
ffi.cdef("""
        void register_thread_callback(int (*func)());
        """)

lib = ffi.dlopen("libtest.dylib")

# crashes here
def test_thread_callback():
        print 'thread call back OK'
        return 0

thread_func = ffi.callback("int()", test_thread_callback)

lib.register_thread_callback(thread_func)

while True:
        pass

________________________________________
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