contributed by <abba123
>
OS : ubuntu 16.04.1 LTS
ref:
http://openhome.cc/Gossip/DesignPattern/ThreadPool.htm
http://swind.code-life.info/posts/c-thread-pool.html
在一般使用 thread 的時候,當一個請求到來,就會建立一個新的 thread,用完之後,便不再使用。
但 thread 的建立需要系統資源,對於一個接受許多請求的情況,就會不斷的建立新執行緒,造成系統效能的降低。
thread pool 的概念就是重複使用建好的 thread。
task_t 裡面包含了要做的 function 和要傳的參數
task_queue 的資料結構,包含了 lock 去控制 task 的執行
thread_pool 裡面包含了所有的 thread 以及 task_queue
sort -R
處理過原本檔案接收的資料是數字,但我們要改成可以接受英文的排序,所以必須要做一點小更動
首先把 node 裡面改成可接受 string
這邊我們改一下判斷式
strcmp 這邊的比較是依照字典排序
剛好符合我們的需求
我們先把原本的資料打散
Makefile 的部份寫了一套自動比較的script
這邊我們用 diff 來比較正確性