上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 29 下一页
摘要: 1 锁 2 Lock() 3 4 Lock(指令锁)是可用的最低级的同步指令。Lock处于锁定状态时,不被特定的线程拥有。Lock包含两种状态——锁定和非锁定,以及两个基本的方法。 5 可以认为Lock有一个锁定池,当线程请求锁定时,将线程至于池中,直到获得锁定后出池。池中的线程处于状态图中的同步阻塞状态。 6 构造方法: 7 Lock() 8 实例方法: 9 acq... 阅读全文
posted @ 2017-07-17 16:20 橙云生 阅读(513) 评论(1) 推荐(0) 编辑
摘要: 1 #!/usr/bin/python 2 #coding=utf-8 3 #线程间通信的同步与互斥操作-锁 4 import threading 5 a=b=0 6 lock=threading.Lock() 7 def value(): 8 while 1: 9 lock.acquire() 10 if a!=b: 11 ... 阅读全文
posted @ 2017-07-17 16:19 橙云生 阅读(220) 评论(1) 推荐(0) 编辑
摘要: 1 #!/usr/bin/python 2 #coding=utf-8 3 4 import threading,time 5 lock=threading.Condition() 6 product=0 7 class Make(threading.Thread): 8 def __init__(self,lock): 9 self.lock=loc... 阅读全文
posted @ 2017-07-17 16:19 橙云生 阅读(256) 评论(0) 推荐(0) 编辑
摘要: 1 #!/usr/bin/python 2 #coding=utf-8 3 #用于线程间通信,通过事件标识控制 4 import threading 5 from time import sleep,ctime 6 7 def A(): 8 print "A is starting" 9 event_is_set=e.wait() 10 print ... 阅读全文
posted @ 2017-07-17 16:18 橙云生 阅读(553) 评论(1) 推荐(0) 编辑
摘要: 1 #!/usr/bin/python 2 #coding=utf-8 3 import os,sys,multiprocessing,time 4 try: 5 os.mkfifo('file') 6 except :pass 7 8 9 def read(): 10 try: 11 os.mkfifo('file1') 12 ex... 阅读全文
posted @ 2017-07-17 16:16 橙云生 阅读(2074) 评论(1) 推荐(0) 编辑
摘要: 1 #!/usr/bin/python 2 #coding=utf-8 3 from time import ctime,sleep 4 import threading 5 6 class Mythead(threading.Thread): 7 def __init__(self,func,args,name=''): 8 super(Mythea... 阅读全文
posted @ 2017-07-17 16:16 橙云生 阅读(647) 评论(1) 推荐(0) 编辑
摘要: 1 #!/usr/bin/python 2 import multiprocessing,time 3 4 def A(cond): 5 name=multiprocessing.current_process().name 6 print "starting",name 7 with cond: 8 print "%s is done... 阅读全文
posted @ 2017-07-17 16:12 橙云生 阅读(595) 评论(1) 推荐(0) 编辑
摘要: 1 #!/usr/bin/python 2 import threading,time 3 4 def Music(): 5 print "music is playing" 6 time.sleep(3) 7 8 def Movie(): 9 print "Movieis playing" 10 time.sleep(5) 11 12 ... 阅读全文
posted @ 2017-07-17 16:12 橙云生 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 1 #!/usr/bin/python 2 from multiprocessing import Process,Lock 3 import time,sys 4 5 def A(lock): 6 with lock: 7 for i in range(10): 8 time.sleep(2) 9 s... 阅读全文
posted @ 2017-07-17 16:11 橙云生 阅读(421) 评论(0) 推荐(0) 编辑
摘要: 1 #!/usr/bin/python 2 from multiprocessing import Process,Event 3 import os,time 4 5 def A(e): 6 print "block Process :starting" 7 e.wait() 8 print "event is set >>",e.is_set() ... 阅读全文
posted @ 2017-07-17 16:10 橙云生 阅读(1125) 评论(0) 推荐(0) 编辑
上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 29 下一页