yield()

概要

yield()は、他のタスクに制御を移すために自らCPUを放棄するための関数です。ただし、Arduino Unoでは実際には何もしません。

ソースコード

yield()は、hardware/arduino/avr/cores/arduino/hooks.c に定義されています。以下に全ソースコードを示します。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
/**
 * Empty yield() hook.
 *
 * This function is intended to be used by library writers to build
 * libraries or sketches that supports cooperative threads.
 *
 * Its defined as a weak symbol and it can be redefined to implement a
 * real cooperative scheduler.
 */
static void __empty() {
    // Empty
}
void yield(void) __attribute__ ((weak, alias("__empty")));

yield()は__empty()と定義されていて、__empty()は何もしない関数です。

attributeにweakが指定されているため、ユーザがこの関数を再定義することができます。

バージョン

Arduino AVR Boards 1.8.6

最終更新日

March 21, 2023

inserted by FC2 system