Commits

Remi Meier  committed 32ea48a

improve hack for thread-limit in raytrace.py

  • Participants
  • Parent commits 0a47a91

Comments (0)

Files changed (2)

File mandelbrot/mandelbrot.py

     threads = int(threads)
     ar, ai = -2.0, -1.5
     br, bi = 1.0, 1.5
-    width, height = 512, 512
+    width, height = 4096, 4096
 
     step = (bi - ai) / threads
     res = []

File raytrace/raytrace.py

 
 from math import sqrt, pow, pi
 from common.abstract_threading import atomic, Future
+import time
 
 AMBIENT = 0.1
 GAMMA_CORRECTION = 1/2.2
             int(pow(color.z/255.0,factor)*255))
 
 
+tasks = 0
 def task(x, h, cameraPos, objs, lightSource):
     with atomic:
         for y in range(h):
                       (Vector(x/50.0-5,y/50.0-5,0)-cameraPos).normal())
             trace(ray, objs, lightSource, 10)
 
+    # force a transaction break. updating a global var should
+    # be done in a separate transaction:
+    time.sleep(0.0)
+    
+    global tasks
+    with atomic:
+        tasks -= 1
+
 futures = []
 def future_dispatcher(ths, *args):
-    if len(futures) >= ths:
-        for f in futures:
-            f()
-        del futures[:]
+    while tasks >= ths:
+        time.sleep(0.0)
 
+    global tasks
+    with atomic:
+        tasks += 1
     futures.append(Future(task, *args))
 
 
 
 
-def run(ths=4, w=300, h=300):
+def run(ths=2, w=600, h=600):
     ths = int(ths)
     w = int(w)
     h = int(h)