⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 badexit2.c.bak

📁 unix环境高级编程(第二版)源代码
💻 BAK
字号:
#include "apue.h"#include <pthread.h>struct foo {	int a, b, c, d;};voiderr_quit(const char *fmt, ...){	va_list		ap;//	va_start(ap, fmt);//	err_doit(0, 0, fmt, ap);//	va_end(ap);	exit(1);}voidprintfoo(const char *s, const struct foo *fp){	printf(s);	printf("  structure at 0x%x\n", (unsigned)fp);	printf("  foo.a = %d\n", fp->a);	printf("  foo.b = %d\n", fp->b);	printf("  foo.c = %d\n", fp->c);	printf("  foo.d = %d\n", fp->d);}void *thr_fn1(struct foo *fo_str){	*fo_str = {1, 2, 3, 4};	printfoo("thread 1:\n", fo_str);	pthread_exit((void *)fo_str);}void *thr_fn2(void *arg){	printf("thread 2: ID is %d\n", pthread_self());	pthread_exit((void *)0);}intmain(void){	int			err;	pthread_t	tid1, tid2;	struct foo fo_str;	err = pthread_create(&tid1, NULL, thr_fn1, &fo_str);	if (err != 0)		err_quit("can't create thread 1: %s\n", strerror(err));	err = pthread_join(tid1, (void *)&fp);	if (err != 0)		err_quit("can't join with thread 1: %s\n", strerror(err));	sleep(1);	printf("parent starting second thread\n");	err = pthread_create(&tid2, NULL, thr_fn2, NULL);	if (err != 0)		err_quit("can't create thread 2: %s\n", strerror(err));	sleep(1);	printfoo("parent:\n", fp);	exit(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -