漂亮的代码,忍不住拿出来
来源:互联网 发布:淘宝网户外用品 编辑:程序博客网 时间:2024/04/27 18:44
uint32_t i;task void computeTask() { uint32_t start = i; for (;i < start + 10000 && i < 400001; i++) {} if (i >= 400000) { i = 0; } else { post computeTask(); }}
This code breaks the compute task up into many smaller tasks. Each invocation of computeTask runs through
10,000 iterations of the loop. If it hasn't completed all 400,001 iterations, it reposts itself. Compile this code and
run it; it will run fine on both Telos and mica-family motes.
Note that using a task in this way required including another variable (i) in the component. Because
computeTask() returns after 10,000 iterations, it needs somewhere to store its state for the next invocation. In
this situation, i is acting as a static function variable often does in C. However, as nesC component state is
completely private, using the static keyword to limit naming scope is not as useful. This code, for example, is
equivalent:
task void computeTask() { static uint32_t i; uint32_t start = i; for (;i < start + 10000 && i < 400001; i++) {} if (i >= 400000) { i = 0; } else { post computeTask(); }}
下面的这部分则是关于Split-Phase Operations的:
In a blocking system, when a program calls a long-running operation, the call does not return until the
operation is complete: the program blocks. In a split-phase system, when a program calls a long-running
operation, the call returns immediately, and the called abstraction issues a callback when it completes.
This approach is called split-phase because it splits invocation and completion into two separate phases
of execution. Here is a simple example of the difference between the two:
Blocking:if (send() == SUCCESS) { sendCount++;}Split-Phase:// start phasesend(); //completion phasevoid sendDone(error_t err) { if (err == SUCCESS) { sendCount++; }}
- 漂亮的代码,忍不住拿出来
- 自动拿出上一次保存的html代码来
- 那年大二的基础LinuxC代码,拿出来就是来丢人的哈哈哈
- 拿出证据来,缴枪的不杀
- 一道机试题,拿出来和大家分享一下,稍候贴出我做的代码(C#)
- 拿出一万个小时来!
- 拿出来分享下
- 拿出点实际行动来
- JavScript 的笔记 拿出来和大家分享下
- jJavaScript 第二部分的 笔记 拿出来分享啦
- 小小的php验证码程序(拿出来晒晒)
- 把word文档中的图片拿出来的小小经历
- 处世态度(有空的时候拿出来读一下)
- 写的一些推广方法 拿出来分享下
- 在大学时的分布式数据库读书笔记 拿出来分享
- 实战将用户的权限一次性拿出来
- 很老的帖子了,拿出来温习一下~~ ^-^
- 漂亮的代码
- javascript克隆table中的元素
- cross compile host,build,target
- Git学习(1)
- Android使用tcpdump抓包
- LINUX IPTABLES 规则详解
- 漂亮的代码,忍不住拿出来
- apache开启.htaccess及.htaccess的使用方法
- VC中用MFC简单创建ActiveX控件
- 如何在ckeditor中实现编辑器和数据库相连。
- 进程静音,暂停,加速的实现
- android Relative Layout 属性
- 图像梯度
- solr全文搜索
- Android Notification 使用详解之二:可更新进度的通知