Use of threading with cffi

Issue #349 resolved
Former user created an issue

I'm trying to use a CFFI built extension in combination with concurrent.futures.ThreadPoolExecutor. The initial code is here:

https://github.com/cjw85/scrappie/tree/python/python

and to my knowledge is working correctly in the absence of threading. When adding a thread pool to the entry point in this code segfaults start occurring.

I started trying to poke around with little success so instead created a fairly minimal CFFI extension:

https://github.com/cjw85/cffi_thread

Running the cffi_thread entry point here can produce non-deterministic results, though usually something like:

$ cffi_thread
0 b'news'
1 b'news'
2 b'news'
3 b'news'
4 b'news'
5 b'news'
6 b'news'
7 b'news'
8 b'news'
9 b'news'

The cffi_nothread entry point gives the expected:

$ cffi_nothread
0 b'root'
1 b'daemon'
2 b'bin'
3 b'sys'
4 b'sync'
5 b'games'
6 b'man'
7 b'lp'
8 b'mail'
9 b'news'

I've checked previous issues, the only similar report seemed to be back from 2013. The lack of reports makes me think I've miss understood something. Have I or is this a bug in CFFI?

Comments (5)

  1. Chris Wright

    Thanks, the C code is usually used with OMP; I believe it is threadsafe. The function I'm running under a thread pool is analogous to that run under OMP in the parent C project. I must have done something dumb along the way. You can close this issue.

  2. Log in to comment