Hello everyone, For my internship<http://morepypy.blogspot.com/2012/12/pypy-related-internship-at-ncar.html>, I am working on implementing a solver for partial differential equations in RPython <https://github.com/seanfisk/rpython-stencil-language>. I am investigating the possibility of parallelizing the code using multi-threading.
I have found the RPython's basic threading library, rpython/rlib/rthread.py<https://bitbucket.org/pypy/pypy/src/a75c05b8580ec08fb12777332492254c57ebe0aa/rpython/rlib/rthread.py?at=default>, and am attempting to get a "Hello world!" threading program up and running. I have successfully been able to start threads that do really simple things like printing literal messages. However, I would now like to be able to pass parameters to the threads. The only example I can seem to find of this library in use is the threading support in PyPy (at pypy/module/thread/os_thread.py<https://bitbucket.org/pypy/pypy/src/a75c05b8580ec08fb12777332492254c57ebe0aa/pypy/module/thread/os_thread.py?at=default>). I‘ve read through the code a number of times and am using it as a reference. However, there are some features I don’t need and some things that simply won't run in my interpreter (e.g., everything involving spaces). Can anybody point me in the right direction as to passing parameters to threads? I know I need something similar to the Bootstrapper to synchronize my parameters, but everything I've tried so far has either not synchronized or segfaulted. The current code is segfaulting around rthread.gc_thread_die(). I can do some more digging on this if necessary. Thanks in advance for help anyone might offer. ~ Sean $ python --version Python 2.7.3 (5acfe049a5b0, May 21 2013, 13:47:22) [PyPy 2.0.2 with GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] Here is the current code: # rthread_hello.py## Compile with: rpython --thread rthread_hello.py from rpython.rlib import rthread # "Library" code class Arguments(object): pass class FunctionData(object): args = Arguments() func = None lock = None _function_data = FunctionData() def _thread_func_wrapper(): rthread.gc_thread_start() func = _function_data.func args = _function_data.args _function_data.lock.release() func(args) rthread.gc_thread_die() def run_in_thread(func, args): _function_data.func = func _function_data.args = args if _function_data.lock is None: _function_data.lock = rthread.allocate_lock() _function_data.lock.acquire(True) rthread.gc_thread_prepare() rthread.start_new_thread(_thread_func_wrapper, ()) # "User" code def func_to_call(args): print 'Within the function' print args.first print args.second def main(argv): for i in xrange(5): args = Arguments() # Create some dummy arguments. args.first = i args.second = i * 10 # Start the thread. run_in_thread(func_to_call, args) return 0 def target(x, y): return main, None
_______________________________________________ pypy-dev mailing list pypy-dev@python.org http://mail.python.org/mailman/listinfo/pypy-dev