-
Notifications
You must be signed in to change notification settings - Fork 0
/
threadc.py
37 lines (32 loc) · 1.07 KB
/
threadc.py
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
37
'''
Created on 10 Sep 2014
@author: gustavo
'''
import threading
from reduction import Reduction
class ThreadCount(threading.Thread):
def __init__(self, threadID, locker, lockscreen, polynomials, save):
threading.Thread.__init__(self)
self.threadID = threadID
self.locker = locker
self.polynomials = polynomials
self.save = save
self.lockscreen = lockscreen
def run(self):
print "Starting thread: " + str(self.threadID) + '\n'
for i in self.polynomials:
reduc = Reduction()
self.lockscreen.acquire()
print 'Thread: '+ str(self.threadID) + ' Doing: ' + str(i.coefs())
self.lockscreen.release()
count = reduc.reduction(i.coefs())
self.locker.acquire()
r = str(i.coefs()) + ":" + str(count)
f = open(self.save, "a")
f.write(r + '\n')
f.close()
self.locker.release()
self.lockscreen.acquire()
#print r
self.lockscreen.release()
del reduc