Created
October 13, 2017 23:45
-
-
Save amraks/a775f96f2fc2a65041d04f28479e457c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
c = threading.Condition() | |
arr = [i-1 for i in range(1, 101)] | |
def odd(): | |
for i in range(1, 100, 2): | |
with c: | |
print 'odd: ', arr[i] | |
c.notify() | |
c.wait() | |
def even(): | |
for i in range(0, 100, 2): | |
with c: | |
print 'even: ', arr[i] | |
c.notify() | |
c.wait() | |
with c: | |
c.notify() | |
t1 = threading.Thread(target=even) | |
t2 = threading.Thread(target=odd) | |
t1.start() | |
t2.start() | |
t1.join() | |
t2.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment