# [pypy-svn] r23280 - pypy/dist/pypy/lib/logic/computation_space

auc at codespeak.net auc at codespeak.net
Mon Feb 13 15:42:45 CET 2006

```Author: auc
Date: Mon Feb 13 15:42:38 2006
New Revision: 23280

Modified:
pypy/dist/pypy/lib/logic/computation_space/test_variable.py
pypy/dist/pypy/lib/logic/computation_space/variable.py
Log:

Modified: pypy/dist/pypy/lib/logic/computation_space/test_variable.py
==============================================================================
--- pypy/dist/pypy/lib/logic/computation_space/test_variable.py	(original)
+++ pypy/dist/pypy/lib/logic/computation_space/test_variable.py	Mon Feb 13 15:42:38 2006
@@ -130,7 +130,6 @@
assert reductor.result == 725760

def test_daisychain_stream(self):
-        # chained stupidity
sp = space.ComputationSpace(dummy_problem)

@@ -162,3 +161,43 @@

assert woman.result == 6

+        sp = space.ComputationSpace(dummy_problem)
+
+            n=N.get()
+            assert 0 < n < 32768
+            l = v.Pair(0, None)
+            L.bind(l)
+            for i in range(1,n):
+                l.set_rest(v.Pair(i, None))
+                l = l.rest()
+            l.set_rest(v.NoValue)
+
+            l=L.get()
+            while l != v.NoValue:
+                val = l.first()
+                l = l.rest()
+
+        L = sp.var('L')
+        N = sp.var('N')
+
+        generator = FunThread(generate, L, N)
+
+        r1.start()
+        r2.start()
+        r3.start()
+        generator.start()
+
+        N.bind(42)
+
+        generator.join()
+        for r in (r1, r2, r3):
+            r.join()
+            assert r.result == 861

Modified: pypy/dist/pypy/lib/logic/computation_space/variable.py
==============================================================================
--- pypy/dist/pypy/lib/logic/computation_space/variable.py	(original)
+++ pypy/dist/pypy/lib/logic/computation_space/variable.py	Mon Feb 13 15:42:38 2006
@@ -137,6 +137,9 @@
def first(self):
return self._car

+    def set_first(self, first):
+        self._cdr = first
+
def rest(self):
return self._cdr

@@ -203,6 +206,31 @@
curr = curr.rest()

+class CList(Pair):
+    """A List supporting concurrent access"""
+
+    def __init__(self, *args):
+        Pair.__init__(*args)
+
+    def set_rest(self, rest):
+        self.last_condition.acquire()
+        try:
+            self._cdr = rest
+            self.last_condition.notifyAll()
+        finally:
+            self.last_condition.release()
+
+    def rest(self):
+        self.last_condition.acquire()
+        try:
+            while self._cdr == None:
+                self.condition.wait()
+            return self._cdr
+        finally:
+            self.last_condition.release()
+
+
class Stream(object):
"""A FIFO stream"""

```