📄 pt-doc.txt
字号:
/**\defgroup pt Protothreads @{ Protothreads are implemented in a single header file, pt.h, whichincludes the local continuations header file, lc.h. This file in turnincludes the actual implementation of local continuations, whichtypically also is contained in a single header file.*//** @} *//**\defgroup examples Examples@{\section example-small A small exampleThis first example shows a very simple program: two protothreadswaiting for each other to toggle two flags. The code illustrates howto write protothreads code, how to initialize protothreads, and how toschedule them.\include example-small.c\section example-code-lock A code-lockThis example shows how to implement a simple code lock - the kind ofdevice that is placed next to doors and that you have to push a fourdigit number into in order to unlock the door.The code lock waits for key presses from a numeric keyboard and if thecorrect code is entered, the lock is unlocked. There is a maximum timeof one second between each key press, and after the correct code hasbeen entered, no more keys must be pressed for 0.5 seconds before thelock is opened.\include example-codelock.c\section example-buffer The bounded buffer with protothread semaphoresThe following example shows how to implement the bounded bufferproblem using the protothreads semaphore library. The example usesthree protothreads: one producer() protothread that produces items,one consumer() protothread that consumes items, and onedriver_thread() that schedules the producer and consumer protothreads.Note that there is no need for a mutex to guard the add_to_buffer()and get_from_buffer() functions because of the implicit lockingsemantics of protothreads - a protothread will never be preempted andwill never block except in an explicit PT_WAIT statement.\include example-buffer.c*//** @} */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -