模块三
***来源:www.luffycity.com***
1.TCP 三次握手的过程
客户端 服务端
1. SYN-SENT --> <seq=100><CTL=SYN> --> SYN-RECEIVED
2. ESTABLISHED <-- <seq=300><ack=101><CTL=SYN,ACK> <-- SYN-RECEIVED
3. ESTABLISHED --> <seq=101><ack=301><CTL=ACK> --> ESTABLISHED
At this point, both the client and server have received an acknowledgment of the connection.
The steps 1, 2 establish the connection parameter (sequence number)
for one direction and it is acknowledged.
The steps 2, 3 establish the connection parameter (sequence number)
for the other direction and it is acknowledged. With these, a full-duplex communication is established.
2.什么是死锁?
由于资源争夺所发生的死锁,会导致程序变成阻塞的状态。
A获取了一个锁,B也获取了一个锁,A要去获取B的锁,B也要去获取A的锁,就会造成死锁。
3.基于threading模块实现将foo函数和bar函数并发运行并计算总共运行时间
import time
import threading
def foo():
print("foo开始")
time.sleep(3)
print("foo结束")
def bar():
print("bar开始")
time.sleep(5)
print("bar结束")
func_list = [foo,bar]
thread_list = []
start_time = time.time()
for func in func_list:
t = threading.Thread(target=func)
t.start()
thread_list.append(t)
for t in thread_list:
t.join()
end_time = time.time()
print(end_time-start_time)