Re: [pypy-dev] Any Multithreading Primitives?
In a message of Tue, 15 Mar 2011 10:04:04 EST, Timothy Baldridge writes:
Does PyPy have any sort of multithreading primitives that are available in rpython programs? I'm specifically looking for CAS. I can probably simulate a mutex with CAS. Or do I have to drop down to some sort of assembly generation to atomically update a object reference?
Thanks,
Timothy
Will anything written here: http://codespeak.net/pypy/dist/pypy/doc/stackless.html be of any use to you? Note, this documentation isquite old and needs attention, and right now the stackless transform does not work with the JIT. changing things so that it would work doesn't seem to be that much work, though, we just haven't gotten around to it. Laura
Will anything written here: http://codespeak.net/pypy/dist/pypy/doc/stackless.html be of any use to you? Note, this documentation isquite old and needs attention, and right now the stackless transform does not work with the JIT. changing things so that it would work doesn't seem to be that much work, though, we just haven't gotten around to it.
Not really. What I need are CAS operations so I can do the following: while(True): oldval = var newval = oldval + 1 if cas(oldval, newval, var): break Basically cas takes the value you think var currently has, the value you want var to be, and the var. Cas then updates var if and only if var's current value == oldvar. But cas is atomic. So basically it returns false if the cas failed, and true if it worked. Using cas you can build mutexes, shared objects, etc. http://en.wikipedia.org/wiki/Compare-and-swap Timothy
Hi, 2011/3/15 Timothy Baldridge <tbaldridge@gmail.com>:
Basically cas takes the value you think var currently has, the value you want var to be, and the var. Cas then updates var if and only if var's current value == oldvar. But cas is atomic. So basically it returns false if the cas failed, and true if it worked. Using cas you can build mutexes, shared objects, etc.
In pypy/module/thread/ll_thread.py, allocate_lock() creates a Lock object, similar to the Python's thread.Lock. Careful though with threads: most of PyPy's garbage collectors are not thread-safe. -- Amaury Forgeot d'Arc
how about dict.setdefault or dict.popitem as a quick hack? unless you are trying to get rid of gil, in which case, sorry I missed your point On 15 March 2011 09:04, Timothy Baldridge <tbaldridge@gmail.com> wrote:
Will anything written here: http://codespeak.net/pypy/dist/pypy/doc/stackless.html be of any use to you? Note, this documentation isquite old and needs attention, and right now the stackless transform does not work with the JIT. changing things so that it would work doesn't seem to be that much work, though, we just haven't gotten around to it.
Not really. What I need are CAS operations so I can do the following:
while(True): oldval = var newval = oldval + 1 if cas(oldval, newval, var): break
Basically cas takes the value you think var currently has, the value you want var to be, and the var. Cas then updates var if and only if var's current value == oldvar. But cas is atomic. So basically it returns false if the cas failed, and true if it worked. Using cas you can build mutexes, shared objects, etc.
http://en.wikipedia.org/wiki/Compare-and-swap
Timothy _______________________________________________ pypy-dev@codespeak.net http://codespeak.net/mailman/listinfo/pypy-dev
participants (4)
-
Amaury Forgeot d'Arc
-
Dima Tisnek
-
Laura Creighton
-
Timothy Baldridge