⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pt-mainpage.txt

📁 这是一个用于创建多线程的程序
💻 TXT
字号:
/**\mainpage The Protothreads Library\author Adam Dunkels <adam@sics.se>Protothreads are a type of lightweight stackless threads designed forseverly memory constrained systems such as deeply embedded systems orsensor network nodes. Protothreads provides linear code execution forevent-driven systems implemented in C. Protothreads can be used withor without an RTOS.Protothreads are a extremely lightweight, stackless type of threadsthat provides a blocking context on top of an event-driven system,without the overhead of per-thread stacks. The purpose of protothreadsis to implement sequential flow of control without complex statemachines or full multi-threading. Protothreads provides conditionalblocking inside C functions.Main features:    - No machine specific code - the protothreads library is pure C    - Does not use error-prone functions such as longjmp()            - Very small RAM overhead - only two bytes per protothread        - Can be used with or without an OS        - Provides blocking wait without full multi-threading or      stack-switchingExamples applications:    - Memory constrained systems        - Event-driven protocol stacks        - Deeply embedded systems        - Sensor network nodes\sa \ref examples "Example programs"  \sa \ref pt "Protothreads API documentation"    The protothreads library is released under a BSD-style license thatallows for both non-commercial and commercial usage. The onlyrequirement is that credit is given.More information and new version of the code can be found at theProtothreads homepage:		     http://www.sics.se/~adam/pt/\section authors AuthorsThe protothreads library was written by Adam Dunkels <adam@sics.se>with support from Oliver Schmidt <ol.sc@web.de>.\section using Using protothreadsUsing protothreads in a project is easy: simply copy the files pt.h,lc.h and lc-switch.h into the include files directory of the project,and \#include "pt.h" in all files that should use protothreads.\section pt-desc ProtothreadsProtothreads are a extremely lightweight, stackless threads thatprovides a blocking context on top of an event-driven system, withoutthe overhead of per-thread stacks. The purpose of protothreads is toimplement sequential flow of control without using complex statemachines or full multi-threading. Protothreads provides conditionalblocking inside a C function.In memory constrained systems, such as deeply embedded systems,traditional multi-threading may have a too large memory overhead. Intraditional multi-threading, each thread requires its own stack, thattypically is over-provisioned. The stacks may use large parts of theavailable memory.The main advantage of protothreads over ordinary threads is thatprotothreads are very lightweight: a protothread does not require itsown stack. Rather, all protothreads run on the same stack and contextswitching is done by stack rewinding. This is advantageous in memoryconstrained systems, where a stack for a thread might use a large partof the available memory. A protothread only requires only two bytes ofmemory per protothread. Moreover, protothreads are implemented in pureC and do not require any machine-specific assembler code.A protothread runs within a single C function and cannot span overother functions. A protothread may call normal C functions, but cannotblock inside a called function. Blocking inside nested function callsis instead made by spawning a separate protothread for eachpotentially blocking function. The advantage of this approach is thatblocking is explicit: the programmer knows exactly which functionsthat block that which functions the never blocks.Protothreads are similar to asymmetric co-routines. The maindifference is that co-routines uses a separate stack for eachco-routine, whereas protothreads are stackless. The most similarmechanism to protothreads are Python generators. These are alsostackless constructs, but have a different purpose. Protothreadsprovides blocking contexts inside a C function, whereas Pythongenerators provide multiple exit points from a generator function.\section pt-autovars Local variables\note Because protothreads do not save the stack context across a blockingcall, local variables are not preserved when the protothreadblocks. This means that local variables should be used with utmostcare - if in doubt, do not use local variables inside a protothread!\section pt-scheduling SchedulingA protothread is driven by repeated calls to the function in which theprotothread is running. Each time the function is called, theprotothread will run until it blocks or exits. Thus the scheduling ofprotothreads is done by the application that uses protothreads.\section pt-impl ImplementationProtothreads are implemented using local continuations. A localcontinuation represents the current state of execution at a particularplace in the program, but does not provide any call history or localvariables. A local continuation can be set in a specific function tocapture the state of the function. After a local continuation has beenset can be resumed in order to restore the state of the function atthe point where the local continuation was set.Local continuations can be implemented in a variety of ways:   -# by using machine specific assembler code,   -# by using standard C constructs, or   -# by using compiler extensions. The first way works by saving and restoring the processor state,except for stack pointers, and requires between 16 and 32 bytes ofmemory per protothread. The exact amount of memory required depends onthe architecture.The standard C implementation requires only two bytes of state perprotothread and utilizes the C switch() statement in a non-obvious waythat is similar to Duff's device. This implementation does, however,impose a slight restriction to the code that uses protothreads: aprotothread cannot perform a blocking wait (PT_WAIT_UNTIL() orPT_YIELD()) inside a switch() statement.Certain compilers has C extensions that can be used to implementprotothreads. GCC supports label pointers that can be used for thispurpose. With this implementation, protothreads require 4 bytes of RAMper protothread.*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -