上节中我们已经掌握了创建大量内核线程的能力,可惜线程之间还缺乏配合。要知道学习ITC(inter thread communication),和学习IPC(inter process communication)一样,不是件简单的事情。本节就暂且解释一种最简单的线程同步手段—completion。
打开include/linux/completion.h,你就会看到completion使用的全部API。这里简单介绍一下。
structcompletion{unsignedintdone;wait_queue_head_twait;};voidinit_completion(structcompletion*x);voidwait_for_completion(structcompletion*x);voidwait_for_completion_interruptible(structcompletion*x);voidwait_for_completion_killable(structcompletion*x);unsignedlongwait_for_completion_timeout(structcompletion*x,unsignedlongtimeout);unsignedlongwait_for_completion_interruptible_timeout(structcompletion*x,unsignedlongtimeout);booltry_wait_for_completion(structcompletion*x);boolcompletion_done(structcompletion*x);voidcomplete(structcompletion*x);voidcomplete_all(structcompletion*x);