- 论坛徽章:
- 0
|
about thread
- #ifdef HAVE_CONFIG_H
- #include <config.h>;
- #endif
- #include <stdio.h>;
- #include <stdlib.h>;
- #include<pthread.h>;
- struct student
- {
- char name;
- int num;
- };
- void *hello(void *arg)
- {
- struct student *student2;
- student2 = (struct student *) arg;
- student2->;name='b';
- student2->;num=2;
- pthread_exit (0);
- }
- main ()
- {
- pthread_t tid;
- struct student *student1;
- student1=malloc(sizeof(struct student));
- student1->;name = 'a';
- student1->;num = 1;
- pthread_create (&tid, NULL,hello, (void *)student1);
- //省略返回值判断..
- pthread_join (tid, NULL);
- //省略返回值判断...
- printf("%c %d\n",student1->;name,student1->;num);
- }
复制代码 |
|