[Stackless] atomic
Alberto Ganesh Barbati
AlbertoBarbati at libero.it
Tue Sep 16 01:56:41 CEST 2008
Richard Tew ha scritto:
> On Mon, Sep 15, 2008 at 5:44 PM, Alberto Ganesh Barbati
> <AlbertoBarbati at libero.it> wrote:
>> By the way, will stackless provide context manager for atomicity to be
>> used in the "with" statement? I mean, wouldn't it be good to be able to
>> write:
>>
>> with stackless.atomic():
>> your_code_here()
>>
>> instead of:
>>
>> t = stackless.getcurrent()
>> flag = t.set_atomic(True)
>> try:
>> your_code_here()
>> finally:
>> t.set_atomic(flag)
>>
>> I know it's not difficult for a user to write such a context manager,
>> but it would be nice to have it provided by stackless itself.
>
> 'stackless' is a C extension module. This 'atomic' object would have
> to be written in C. Not many people use the atomic features, as
> indicated by the fact you're the first I have heard of in a long time.
>
> We would be more than happy to provide a context manager, if you (or
> anyone for that matter) provided patches to add it, given the patches
> were of sufficient quality.
>
I know that stackless is a C module. Unfortunately I am not well versed
with the python C bindings to write a patch (I mostly use C++ via
Boost.Python), but the manager I'm speaking about is really this simple:
class atomic:
def __enter__(self):
self.flag = getcurrent().set_atomic(True)
def __exit__(self, exc_type, exc_value, traceback):
getcurrent().set_atomic(self.flag)
HTH,
Ganesh
More information about the Stackless
mailing list