Synchronization Mechanism: Completion

Table of Contents

1 Completions Introduction

In the case some activity is initiated outside of the current thread, and then waiting for that activity to complete, it can be tempting to use a semaphore for synchronization of the two tasks, but it not the best solution in this situation, completions are a lightweight mechanism to allow one thread to tell another that the job is done.

on one side, creating and waiting for the a completiong by calling:

struct completion test_completion;
init_completion(&test_completion);
wait_for_completion(&test_completion);

othe the other side, the actual completion event may be signalled by calling one of the following:

complete(&test_completion);
complete_all(&test_completion);

2 Completion Inplementation

The implementation of completion is based on the wait queue, when wait_ for_ completion is called, current task will be delete from the running _task _list, so current task can't be scheduled by scheduler, when some other task called complete() to signall the waiting event is completed, the task will be put back into the running_ task _list, and it will be schedule in next schedule cycle. the process as following figure showed.

completion.png

Figure 1: The Implementation of Completion

Author: Yanqing Li(Yannik Li)

Created: 2015-11-27 Fri 16:18

Emacs 24.4.1 (Org mode 8.2.10)

Validate