- 论坛徽章:
- 0
|
这个程序可以看出什么在什么地方:
- #include <stdio.h>
- #include <pthread.h>
- int seq = 0;
- void thread0(int v)
- {
- int i;
- while(1) {
- printf("This is a pthread0 stack %p global %p args %p %d\n", &i, &seq, &v, seq++);
- sleep(2);
- }
- }
- void thread1(void)
- {
- int i;
- while(1) {
- printf("This is a pthread1 stack %p %d\n", &i, seq++);
- sleep(2);
- }
- }
- int main(int argc, char **argv)
- {
- pthread_t id[4];
- int i,ret;
- printf("main stack = %p main args =%p\n", &i, &argc);
- ret = pthread_create(&id[0], NULL, (void *)thread0, NULL);
- ret = pthread_create(&id[1], NULL, (void *)thread1, NULL);
- if(ret!=0){
- printf ("Create pthread error!\n");
- exit (1);
- }
- printf("This is the main process.\n");
- pthread_join(id[0],NULL);
- return (0);
- }
复制代码
原帖由 albcamus 于 2005-3-10 09:04 发表
我是看《nptl-design》中这么说的:
如果我没理解错,就应该是这个意思线程数据结构和线程专有数据被放在栈里,传统的栈数据(那些自动变量、函数调用现场等)正好就在上面这2中数据的下边,并往下增长。如果 ... |
|