Give me a piece sky! Give you one Creation! Give us one invention!
  • 2008-06-30

    protothreads ----lightweight ,stackless Threads in C - [技术话题]

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
    http://taurusboy.blogbus.com/logs/23309844.html

      网上 查到 很多免费的 嵌入式 资源 都来这个计算机学院 ,他们的研究成果,带给人类科技的成功 ,同时给大家一个创新的亮点!

       最近看到 PROTOTHREADS 很感兴趣,想研究下去 。对此每日一帖,慰勉自己,记下自己的感悟,和学习心得。  ---You should remember this is free, now free is my god!

    【6-21] 

    Protothreads

    "Many of us use the switch/case construct to explicitly implement concurrent state machines in our code. The [protothread] macros merely provide a level of abstraction above that so that the code appears more linear and the overall logic more visible." Dan Henry summarizes how protothreads work and how they are used in a discussion about protothreads in the 8052 message board at www.8052.com.

      “我们很多人使用 在代码中 使用  switch/case 结构 来明确的实现同时发生的状态机。 PROTOTHREAD 宏 仅仅 提供在此之上 一定程序的抽象化,从而使得代码总体看起来更加清晰和总体逻辑明了 ” Dan Henry 曾经在 www.8052.com 的消息板上总结  protothreads 是怎样工作的,及怎样去使用 中这样描述。
     

    Protothreads are a extremely lightweight, stackless threads that provides a blocking context on top of an event-driven system, without the overhead of per-thread stacks. The purpose of protothreads is to implement sequential flow of control without using complex state machines or full multi-threading. Protothreads provides conditional blocking inside a C function.

    Protothreads 是 超轻量级,无堆栈 线程 ,可提供一个阻塞内容在事件驱动型系统,它没有通常线程堆栈的占用问题。它的主要作用是执行顺序控制流,而无须复杂的状态机或者多线程。 PROTOTHREADS提供条件性阻塞,内嵌在C功能函数内。

    In memory constrained systems, such as deeply embedded systems, traditional multi-threading may have a too large memory overhead. In traditional multi-threading, each thread requires its own stack, that typically is over-provisioned. The stacks may use large parts of the available memory.

     在内存受限的系统内,比如复杂的嵌入式系统,传统的多线程 可能占用很多内存。 在传统的多线程内,每个线程必须拥有它自己的堆栈,典型的不可超越的规则。堆栈可能占用一部分可用内存。

    The main advantage of protothreads over ordinary threads is that protothreads are very lightweight: a protothread does not require its own stack. Rather, all protothreads run on the same stack and context switching is done by stack rewinding. This is advantageous in memory constrained systems, where a stack for a thread might use a large part of the available memory. A protothread only requires only two bytes of memory per protothread. Moreover, protothreads are implemented in pure C and do not require any machine-specific assembler code.

    PROTOTHREADS 主要的特点相比普通的线程,就是它非常小巧;它不需要自己的堆栈。而且,所有的实例运行在同样的堆栈和内容切换通过堆栈反转完成。 在内存限制的系统,就是需要占用可用内存很大一部分的线程堆栈系统而言,就是一个优点。一个 PROTOTHREADS 仅需要两个字节的内存。更多,它全部在纯C代码下执行,不需要任何器和机器汇编代码。

    A protothread runs within a single C function and cannot span over other functions. A protothread may call normal C functions, but cannot block inside a called function. Blocking inside nested function calls is instead made by spawning a separate protothread for each potentially blocking function. The advantage of this approach is that blocking is explicit: the programmer knows exactly which functions that may block that which functions that are not able block.

      

    Protothreads are similar to asymmetric co-routines. The main difference is that co-routines uses a separate stack for each co-routine, whereas protothreads are stackless. The most similar mechanism to protothreads are Python generators. These are also stackless constructs, but have a different purpose. Protothreads provides blocking contexts inside a C function, whereas Python generators provide multiple exit points from a generator function.

     网上关于它的改进--  Building "instant-up" real-time operating systems    http://www.embedded.com/design/207402540?pgno=1

     

     

     

       


    收藏到:Del.icio.us