当前位置:网站首页>【plang 1.4.3】定时器的使用
【plang 1.4.3】定时器的使用
2022-08-02 03:30:00 【ChivenZhang】
以下代码,演示如何使用plang脚本的定时器功能。
import std::IO;
import std::Type;
import std::time::Timer;
import std::time::Task;
import std::time::Timeout;
class Task1 : Task
{
public Task1(){}
public run(){
IO.printf("@ ");
}
}
class Task2 : Task
{
public Task2(){}
public run(){
IO.printf("# ");
}
}
class Test
{
public static main()
{
t->Timer=new Timer(100);
co_start t.start(new Task1(), 6);
co_start t.start(new Task2(), 3);
i->int=0;
while(i++<10)
{
Timeout.sleep(100);
IO.printf("* ");
}
}
}编译完成执行:plang -c Test
输出(可能情况):
情形1:

情形2:

情形3:

解释:代码中使用std::Timer定时器执行两个Task任务,由于采用了co_start原语进行协程分发,所以结果呈现为异步执行。
Plang语言介绍参考:Plang编程语言
边栏推荐
- 【Arduino 连接 SD 卡模块实现数据读写】
- 【Popular Science Post】Detailed explanation of MDIO interface
- AD PCB导出Gerber文件(非常详细的步骤)
- 【水位传感器与 Arduino 连接测量水位】
- 基于阿里云OSS+PicGo的个人图床搭建
- 分割回文串 DP+回溯 (LeetCode-131)
- ICN6211:MIPI DSI转RGB视频转换芯片方案介绍 看完涨知识了呢
- 关于IIC SDA毛刺的那些事
- PCB设计思路
- 【nRF24L01 connects with Arduino to realize wireless communication】
猜你喜欢

简单的RC滤波电路

物联网方案

Arduino lights up nixie tubes

SyntaxError: unexpected character after line continuation character

Industry where edge gateway strong?

完全背包问题(动态规划)

uniCloud use

How to quickly build your own IoT platform?

Personal image bed construction based on Alibaba Cloud OSS+PicGo

Out of memory error on GPU 0. Cannot allocate xxxGB memory on GPU 0, available memory is only xxx
随机推荐
VCA821可变增益放大器
Comparative analysis of mobile cloud IoT pre-research and Alibaba Cloud development
兼容C51与STM32的Keil5安装方法
OneNET Studio与IoT Studio对比分析
Based on the raspberry pie smart luggage development environment set up
Website development plan research
出差电子流应用实战
R语言 —— 多元线性回归
Industry where edge gateway strong?
引擎开发日志:OpenGL资源多线程加载
工业边缘网关究竟强大在哪里?
【Arduino 连接DHT11 湿度和温度传感器】
USB HUB USB集线器电路设计
阿里云华为云对比分析
AD8307对数检波器
[Popular Science Post] I2C Communication Protocol Detailed Explanation - Partial Software Analysis and Logic Analyzer Example Analysis
回溯法 & 分支限界 - 2
【Arduino connects DHT11 humidity and temperature sensor】
《scala 编程(第3版)》学习笔记2
机器学习相关 概率论重点笔记