cyberdelia / atomic Goto Github PK
View Code? Open in Web Editor NEWAn atomic class that guarantees atomic updates to its contained value.
Home Page: https://atomic.readthedocs.org
License: MIT License
An atomic class that guarantees atomic updates to its contained value.
Home Page: https://atomic.readthedocs.org
License: MIT License
In the function Refernce_compare_and_set you call:
InterlockedCompareExchange
however, this funciton is implemented as the compiler intrinsic:
_InterlockedCompareExchange
... see link below
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683560(v=vs.85).aspx
Without this you get the link error:
c:\Users\whodoo\devel\tools>easy_install atomic
Processing atomic
Running setup.py -q bdist_egg --dist-dir c:\Users\whodoo\devel\tools\atomic\e
gg-dist-tmp-mpgowe
_reference.c
atomic/_reference.c(95) : warning C4013: **'InterlockedCompareExchange'** undefined;
assuming extern returning int
atomic/_reference.c(95) : error C2065: 'old_value' : undeclared identifier
error: Setup script exited with error: command '"c:\Program Files (x86)\Microsof
t Visual Studio 9.0\VC\BIN\cl.exe"' failed with exit status 2
I am not sure if you need to include Windows.h, but I also added the following code at the top of _reference.c.
#if defined(_MSC_VER)
#include <Windows.h>
#
Test if C extension works properly on windows.
Make AtomicLongArray
more versatile, allowing more atomic operation to append.
When I'm running python setup.py build, I get this:
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c: In function ‘long_store’:
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c:158:5: warning: implicit declaration of function ‘__atomic_store’ [-Wimplicit-function-declaration]
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c:158:26: error: ‘__ATOMIC_SEQ_CST’ undeclared (first use in this function)
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c:158:26: note: each undeclared identifier is reported only once for each function it appears in
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c: In function ‘long_add_and_fetch’:
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c:161:5: warning: implicit declaration of function ‘__atomic_add_fetch’ [-Wimplicit-function-declaration]
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c:161:37: error: ‘__ATOMIC_SEQ_CST’ undeclared (first use in this function)
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c: In function ‘long_sub_and_fetch’:
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c:164:5: warning: implicit declaration of function ‘__atomic_sub_fetch’ [-Wimplicit-function-declaration]
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c:164:37: error: ‘__ATOMIC_SEQ_CST’ undeclared (first use in this function)
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c: In function ‘long_get_and_set’:
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c:167:5: warning: implicit declaration of function ‘__atomic_exchange_n’ [-Wimplicit-function-declaration]
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c:167:38: error: ‘__ATOMIC_SEQ_CST’ undeclared (first use in this function)
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c: In function ‘long_compare_and_set’:
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c:170:5: warning: implicit declaration of function ‘__atomic_compare_exchange_n’ [-Wimplicit-function-declaration]
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c:170:52: error: ‘__ATOMIC_SEQ_CST’ undeclared (first use in this function)
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c:171:1: warning: control reaches end of non-void function [-Wreturn-type]
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c: In function ‘long_get_and_set’:
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c:168:1: warning: control reaches end of non-void function [-Wreturn-type]
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c: In function ‘long_sub_and_fetch’:
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c:165:1: warning: control reaches end of non-void function [-Wreturn-type]
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c: In function ‘long_add_and_fetch’:
atomic/__pycache__/_cffi__xe6f6e3c8xf914a2ce.c:162:1: warning: control reaches end of non-void function [-Wreturn-type]
Traceback (most recent call last):
File "setup.py", line 9, in <module>
from atomic import ffi
File "/home/harius/dist/atomic-0.7.2/atomic/__init__.py", line 32, in <module>
""")
File "/usr/local/lib/python2.7/dist-packages/cffi/api.py", line 341, in verify
lib = self.verifier.load_library()
File "/usr/local/lib/python2.7/dist-packages/cffi/verifier.py", line 74, in load_library
self._compile_module()
File "/usr/local/lib/python2.7/dist-packages/cffi/verifier.py", line 139, in _compile_module
outputfilename = ffiplatform.compile(tmpdir, self.get_extension())
File "/usr/local/lib/python2.7/dist-packages/cffi/ffiplatform.py", line 25, in compile
outputfilename = _build(tmpdir, ext)
File "/usr/local/lib/python2.7/dist-packages/cffi/ffiplatform.py", line 50, in _build
raise VerificationError('%s: %s' % (e.__class__.__name__, e))
cffi.ffiplatform.VerificationError: CompileError: command 'gcc' failed with exit status 1
I'm on 64-bit Ubuntu 12.04, gcc 4.6.4, python 2.7.3
Hello,
I couldn't install atomic under windows. The problem came from the fact that the verzechnis pycache was included in the distribution and only compiled under Linux. The problem was solved after deleting the directory in the installation archive.
Hi,
It seems the library blocks on OSX 10.8.2 with xcode 4.6
Here's the test script
import logging
from time import sleep
from metrology import Metrology
while True:
timer = Metrology.timer('test')
with timer:
print 'sleep'
sleep(1)
$ python test.py
sleep
^CTraceback (most recent call last):
File "test.py", line 15, in <module>
sleep(1)
File "/Library/Python/2.7/site-packages/metrology/instruments/timer.py", line 40, in __exit__
self.update(duration)
File "/Library/Python/2.7/site-packages/metrology/instruments/timer.py", line 27, in update
self.meter.mark()
File "/Library/Python/2.7/site-packages/metrology/instruments/meter.py", line 13, in wrapper
return method(self, *args, **kwargs)
File "/Library/Python/2.7/site-packages/metrology/instruments/meter.py", line 63, in mark
self.counter.update(lambda v: v + value)
File "/Library/Python/2.7/site-packages/atomic/__init__.py", line 110, in update
old_value = self.ref.get()
KeyboardInterrupt
I'll make some more tests to see if the native works
Thanks
Line 95, in _reference.c has the code:
if (InterlockedCompareExchange(&self->value, new_value, old_value))
The code should read:
if (InterlockedCompareExchange(&self->value, expect_value, new_value)
since old_value is not defined in the function Reference_compare_and_set.
Currently, when building on a windows system the following error is returned during compilation:
atomic/_reference.c(95) : error C2065: 'old_value' : undeclared identifier
error: command '"c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.ex
e"' failed with exit status 2
The atomic.update function leaks memory. To reproduce, run:
from atomic import Atomic
atomic = Atomic(0)
while True:
atomic.update(lambda v: v + 1)
Watch your python process' memory footprint go up.
Python 2.7.2, atomic 0.6 downloaded from pypi.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.