Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2014-11-10 16:50:36 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
91f6dbe47949c4c54767f5d88379e9074b69c808
91f6dbe4
1 parent
4d4e8402
research st, add test for setjmp and longjmp.
隐藏空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
66 行增加
和
0 行删除
trunk/research/arm/jmp_2flow.cpp
trunk/research/arm/jmp_flow.cpp
trunk/research/arm/jmp_2flow.cpp
0 → 100644
查看文件 @
91f6dbe
/*
# http://blog.csdn.net/win_lin/article/details/40948277
# for all supports setjmp and longjmp:
g++ -g -O0 -o jmp_2flow jmp_2flow.cpp
*/
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
jmp_buf
context_thread_0
;
jmp_buf
context_thread_1
;
void
thread0_functions
()
{
int
ret
=
setjmp
(
context_thread_0
);
// when ret is 0, create thread,
// when ret is not 0, longjmp to this thread.
if
(
ret
==
0
)
{
return
;
}
int
age
=
10000
;
const
char
*
name
=
"winlin"
;
printf
(
"[thread0] age=%d, name=%s
\n
"
,
age
,
name
);
if
(
!
setjmp
(
context_thread_0
))
{
printf
(
"[thread0] switch to thread1
\n
"
);
longjmp
(
context_thread_1
,
1
);
}
// crash, for the stack is modified by thread1.
// name = 0x2b67004009c8 <error: Cannot access memory at address 0x2b67004009c8>
printf
(
"[thread0] terminated, age=%d, name=%s
\n
"
,
age
,
name
);
exit
(
0
);
}
void
thread1_functions
()
{
int
ret
=
setjmp
(
context_thread_1
);
// when ret is 0, create thread,
// when ret is not 0, longjmp to this thread.
if
(
ret
==
0
)
{
return
;
}
int
age
=
11111
;
printf
(
"[thread1] age=%d
\n
"
,
age
);
if
(
!
setjmp
(
context_thread_1
))
{
printf
(
"[thread1] switch to thread0
\n
"
);
longjmp
(
context_thread_0
,
1
);
}
printf
(
"[thread1] terminated, age=%d
\n
"
,
age
);
exit
(
0
);
}
int
main
(
int
argc
,
char
**
argv
)
{
thread0_functions
();
thread1_functions
();
// kickstart
longjmp
(
context_thread_0
,
1
);
return
0
;
}
...
...
trunk/research/arm/jmp_flow.cpp
查看文件 @
91f6dbe
/*
# http://blog.csdn.net/win_lin/article/details/40948277
# for all supports setjmp and longjmp:
g++ -g -O0 -o jmp_flow jmp_flow.cpp
*/
...
...
请
注册
或
登录
后发表评论