-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_autostack.c
More file actions
49 lines (45 loc) · 869 Bytes
/
Copy pathexample_autostack.c
File metadata and controls
49 lines (45 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include "co.h"
#define MAXRAND 400
//递归消耗栈
void buf(int loop)
{
uint8_t buff[512];
int i = 0;
int k = 0;
uint8_t c = (uint8_t)loop;
if(c == 0) c = 1;
for(;i<512;i++)
buff[i] = c;
if(loop == 0) {
schedule(); //在栈消耗最大处切换协程
schedule();
return;
}
buf(loop-1);
for(i=0;i<512;i++) {
if(buff[i] != c) k++;
}
if(k)
printf("coid %d, buff %d, %d\n", coid(), buff[0], k);
}
void autostack(void *d)
{
int loop = rand() % MAXRAND;
buf(loop);
buf(loop);
}
void main()
{
int i=0;
srand(time(0));
for(; i<MAXRAND; i++)
cocreate(AUTOSTACK, autostack, NULL);
while(coloop());
}