在examples下面建立一个huge_threads.c的源文件
1 | #include <stdio.h> |
gcc -I../obj -g huge_threads.c ../obj/libst.a -o huge_threads
./huge_threads 10000
./huge_threads 30000
在examples下面建立一个huge_threads.c的源文件
1 | #include <stdio.h> |
gcc -I../obj -g huge_threads.c ../obj/libst.a -o huge_threads
./huge_threads 10000
./huge_threads 30000
比如新增一个用户linweibin
1:新增用户1
2
3
4sudo adduser linweibin
#切换到linweibin目录下面
su linweibin
cd ~
2:添加公钥内容1
2
3
4
5
6
7
8# 1. 建立 ~/.ssh 目录,注意权限需要改为700
mkdir .ssh;
chmod 700 .ssh
# 2. 將公钥内容cat转存到authorized_keys里面
cat /path/id_rsa.pub >> .ssh/authorized_keys
# authorized_keys权限设为644才可以
chmod 644 .ssh/authorized_keys
我们知道可以用goto来实现函数内的跳转,setjmp和longjmp则是用于实现函数外的跳转。
因此可以用setjmp和longjmp来实现C的异常处理或者用于实现协程。
statethreads这个协程库就是基于setjmp和longjmp实现的
setjmp把当前函数的调用环境保存到env中
第一次设置会返回0
当longjmp跳转的时候,会返回longjmp的第二个参数int setjmp (jmp_buf env);
longjmp在当前位置跳转到之前保存的env的环境中void longjmp (jmp_buf env, int val);
来看一个例子1
2
3
4
5
6
7
8
9
10
11
12#include <stdio.h>
#include <setjmp.h>
int main() {
jmp_buf env;
int val;
val=setjmp(env);
printf ("val is %d\n",val);
if (!val)
longjmp(env, 1);
return 0;
}
输出的结果1
2val is 0
val is 1