import threading
import time
import subprocess
defsnmp(a):
time.sleep(5)
print(a)
for a in range(1,249):
threading.Thread(target=snmp,args=(a,), name=a).start()
print("Thread Start:",a)
测试结果:只有在创建线程的时候,us有明显升高,sy仅升高约2%创建完成后随即下降。
结论:sy升高与线程调度无关。
Popen开销
使用如下代码进行测试
import threading
import time
import subprocess
defsnmp(a):
time.sleep(5)
subprocess.Popen(["echo",str(a),], bufsize=0, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
for a in range(1,101):
threading.Thread(target=snmp,args=(a,), name=a).start()
print("Thread Start:",a)
The futex() system call provides a method for waiting untila certain
condition becomes true. It is typically used asa blocking construct
inthe context of shared-memory synchronization. When using futexes,
the majority ofthe synchronization operations are performed in user
space. A user-space program employs the futex() system call only when
it is likely that the program has to block fora longer timeuntilthe
condition becomes true. Other futex() operations can be used to wake
any processes or threads waiting fora particular condition.