轻量C线程框架

Protothreads are extremely lightweight stackless threads designed for severely memory constrained systems, such as small embedded systems or wireless sensor network nodes. Protothreads provide linear code execution for event-driven systems implemented in C. Protothreads can be used with or without an underlying operating system to provide blocking event-handlers. Protothreads provide sequential flow of control without complex state machines or full multi-threading.

#include "pt.h"
 
struct pt pt;
struct timer timer;
 
PT_THREAD(example(struct pt *pt))
{
  PT_BEGIN(pt);
 
  while(1) {
    if(initiate_io()) {
      timer_start(&timer);
      PT_WAIT_UNTIL(pt,
         io_completed() ||
         timer_expired(&timer));
      read_data();
    }
  }
  PT_END(pt);
}
Example protothreads code.

While protothreads originally were created for memory-constrained embedded systems, it has found many uses as a general purpose library too. Examples include multimedia streaming server software, grid computing research software, and MPEG decoding software for Internet TVs.

Read more...

Main features:

  • Very small RAM overhead - only two bytes per protothread and no extra stacks
  • Highly portable - the protothreads library is 100% pure C and no architecture specific assembly code
  • Can be used with or without an OS
  • Provides blocking wait without full multi-threading or stack-switching
  • Freely available under a BSD-like open source license

Example applications:

  • Memory constrained systems
  • Event-driven protocol stacks
  • Small embedded systems
  • Sensor network nodes
  • Portable C applications

For example usages, see the Examples page.

The protothreads library is released under an open source BSD-style license that freely allows for both non-commercial and commercial usage. The only requirement is that credit is given. Download the full source code here.

Protothreads were invented by Adam Dunkels with support from Oliver Schmidt <ol.sc@web.de>.


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值