File: test_Sync.py

package info (click to toggle)
python-extclass 1.2-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 432 kB
  • ctags: 547
  • sloc: ansic: 4,549; python: 134; makefile: 46; sh: 18
file content (36 lines) | stat: -rw-r--r-- 581 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

from Sync import Synchronized
import thread
from rand import rand
from time import sleep


class P(Synchronized):

    def __init__(self,*args,**kw):
	self.count=0

    def inc(self):
	    c=self.count
	    sleep(rand()/327680.0)
	    self.count=self.count+1
	    return c,self.count

    def incn(self,n):
	    c=self.count
	    for i in range(n): self.inc()
	    return c,self.count
	
p=P(1,2,spam=3)

def test():
    
    for i in range(10):
	n=3
	old,new=p.incn(n)
	print old,new
	if old+n != new: print 'oops'


for i in range(10): thread.start_new_thread(test,())
sleep(50)