基本多執行緒的理解

2021-07-06 10:54:50 字數 3353 閱讀 9579

同步:直到一件事徹底做完再繼續另一件事

非同步:不管這件事做沒做完繼續其他的事情  //

同步序列

//    dispatch_queue_t queue = dispatch_queue_create("multithread1", dispatch_queue_serial);

//    for (int i = 0 ; i< 10 ; i++) );

//    } /*

2015-11-05 17:23:51.024 multithreading[5005:269150]   0

2015-11-05 17:23:51.024 multithreading[5005:269150]   1

2015-11-05 17:23:51.024 multithreading[5005:269150]   2

2015-11-05 17:23:51.025 multithreading[5005:269150]   3

2015-11-05 17:23:51.025 multithreading[5005:269150]   4

2015-11-05 17:23:51.025 multithreading[5005:269150]   5

2015-11-05 17:23:51.025 multithreading[5005:269150]   6

2015-11-05 17:23:51.025 multithreading[5005:269150]   7

2015-11-05 17:23:51.025 multithreading[5005:269150]   8

2015-11-05 17:23:51.025 multithreading[5005:269150]   9 */

//非同步序列

//    dispatch_queue_t queue = dispatch_queue_create("multithread1", dispatch_queue_serial);

//    for (int i = 0 ; i< 10 ; i++) );

//    } /*

2015-11-05 17:25:04.878 multithreading[5023:270972]   0

2015-11-05 17:25:04.878 multithreading[5023:270972]   1

2015-11-05 17:25:04.879 multithreading[5023:270972]   2

2015-11-05 17:25:04.879 multithreading[5023:270972]   3

2015-11-05 17:25:04.879 multithreading[5023:270972]   4

2015-11-05 17:25:04.879 multithreading[5023:270972]   5

2015-11-05 17:25:04.880 multithreading[5023:270972]   6

2015-11-05 17:25:04.880 multithreading[5023:270972]   7

2015-11-05 17:25:04.881 multithreading[5023:270972]   8

2015-11-05 17:25:04.881 multithreading[5023:270972]   9 */

//同步並行

//    dispatch_queue_t queue = dispatch_queue_create("queue", dispatch_queue_concurrent);

//    for (int i = 0 ; i< 10 ; i++) );

//    } /*

2015-11-05 17:27:51.973 multithreading[5041:273219]   0

2015-11-05 17:27:51.973 multithreading[5041:273219]   1

2015-11-05 17:27:51.973 multithreading[5041:273219]   2

2015-11-05 17:27:51.974 multithreading[5041:273219]   3

2015-11-05 17:27:51.974 multithreading[5041:273219]   4

2015-11-05 17:27:51.974 multithreading[5041:273219]   5

2015-11-05 17:27:51.974 multithreading[5041:273219]   6

2015-11-05 17:27:51.974 multithreading[5041:273219]   7

2015-11-05 17:27:51.974 multithreading[5041:273219]   8

2015-11-05 17:27:51.974 multithreading[5041:273219]   9 */

//非同步並行

dispatch_queue_t

queue =

dispatch_queue_create

("queue"

, dispatch_queue_concurrent);

for(

inti =

0; i<

10; i++) ); }

/*2015-11-05 17:29:24.295 multithreading[5055:274607]   3

2015-11-05 17:29:24.295 multithreading[5055:274598]   0

2015-11-05 17:29:24.295 multithreading[5055:274599]   1

2015-11-05 17:29:24.295 multithreading[5055:274600]   2

2015-11-05 17:29:24.296 multithreading[5055:274608]   4

2015-11-05 17:29:24.296 multithreading[5055:274607]   5

2015-11-05 17:29:24.296 multithreading[5055:274598]   6

2015-11-05 17:29:24.296 multithreading[5055:274599]   7

2015-11-05 17:29:24.297 multithreading[5055:274600]   8

2015-11-05 17:29:24.297 multithreading[5055:274608]   9 */

ZIP暴力破解指令碼 多執行緒

import zipfile import sys import tkinter as tk import threading import queue class brute zip object def init self self.flag false 用來判斷是否在字典中找到密碼,找到標記成...

多執行緒 理解多執行緒(一)

程序 程序是cpu分配資源的基本單位 執行緒 執行緒是cpu排程的基本單位 資源分配給程序,所有執行緒共享該程序的資源 當執行緒數大於cpu的數量,會出現時間片的輪詢。cpu時間片是直接分配給執行緒的,執行緒拿到cpu時間片就能執行了 cpu時間片不是先分給程序然後再由程序分給程序下的執行緒的。所有...

多執行緒的理解

1.減少了建立和銷毀執行緒的次數,每個工作執行緒都可以被重複利用,可執行多個任務。2.可以根據系統的承受能力,調整執行緒池中工作線執行緒的數目,防止因為消耗過多的記憶體,而把伺服器累趴下 每個執行緒需要大約1mb記憶體,執行緒開的越多,消耗的記憶體也就越大,最後宕機 要配置乙個執行緒池是比較複雜的,...