#多執行緒程式演示
import threading
from random import randint
from time import sleep
import os
import turtle
defdraw_picture
(t,x,y)
:#t物件,x座標,y座標(預設螢幕正中心)
t.speed(10)
#畫速 t.penup(
)#拿筆
t.goto(x,y)
#到指定位置
t.pendown(
)#下筆
t.begin_fill(
)#上色
t.color(
'green'
) t.circle(50)
#畫圓,指定半徑
t.end_fill(
)if __name__ ==
'__main__'
:print
('主線程開始'
) t1 = turtle.turtle(
) t2 = turtle.turtle(
) t3 = turtle.turtle(
) screen = turtle.screen(
)#單執行緒情況下
draw_picture(t1,0,
0)draw_picture(t1,
-200,0
) draw_picture(t1,
200,0)
#開啟事件迴圈
screen.mainloop(
)print
('主線程結束'
#多執行緒程式演示
#多執行緒程式演示
import threading
from random import randint
from time import sleep
import os
import turtle #用來畫圖的
defdraw_picture
(t,x,y)
:#t物件,x座標,y座標(預設螢幕正中心)
t.speed(10)
#畫速 t.penup(
) t.goto(x,y)
#到指定位置
t.pendown(
) t.begin_fill(
)#上色
t.color(
'green'
) t.circle(50)
#畫圓,指定半徑
t.end_fill(
)if __name__ ==
'__main__'
:print
('主線程開始'
) t1 = turtle.turtle(
) t2 = turtle.turtle(
) t3 = turtle.turtle(
) screen = turtle.screen(
)#多執行緒
th1 = threading.thread(target=draw_picture,args=
(t1,0,
0)) th2 = threading.thread(target=draw_picture,args=
(t2,
-200,0
))th3 = threading.thread(target=draw_picture,args=
(t3,0,
200)
) th1.start(
) th2.start(
) th3.start(
)#開啟事件迴圈
screen.mainloop(
)print
('主線程結束'
執行緒 執行緒池 執行緒同步 例項
執行緒 using system using system.collections.generic using system.text using system.threading namespace 執行緒thread public void threadmain data static void...
多執行緒,執行緒鎖,例項
多執行緒可以分多條執行緒,同時執行程式,但也因此出現一些問題,通過執行緒鎖可以解決 包子例項 廚師做包子,顧客吃包子,多餘50個包子廚師停止做包子,包子為零顧客停止吃包子,當廚師做到10個後顧客可以吃包子 顧客類 customer.class public class customer implem...
多執行緒例項
include include include include define max 10 pthread t thread 2 pthread mutex t mut int number 0,i void thread1 printf thread1 主函式在等我完成任務嗎?n pthread ...