Skip to content

Commit

Permalink
test atomic threading
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@23220 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jul 19, 2019
1 parent 0d792ea commit 4df0a73
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/unittests/unit/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,31 @@ def _test_IntegerClass(self, IntegerClass):

def test_AtomicInteger(self):
self._test_IntegerClass(AtomicInteger)
#TODO: test lock with threading

def test_AtomicInteger_threading(self):
a = AtomicInteger()
N = 5000
def increase():
for _ in range(N):
a.increase()
def decrease():
for _ in range(N):
a.decrease()
T = 20
from threading import Thread
threads = []
for i in range(T):
if i%2==0:
target = increase
else:
target = decrease
t = Thread(target=target, name=str(target))
t.daemon = True
threads.append(t)
for t in threads:
t.start()
for t in threads:
t.join()

def test_MutableInteger(self):
self._test_IntegerClass(MutableInteger)
Expand Down

0 comments on commit 4df0a73

Please sign in to comment.