The source for simple.c looks a little nastier than it needs to. For example, much of the code is related to error checking of the pthread_xxx calls. To help eliminate some of this clutter, I have written a small library of macros and C code to hide some of these details. The macros and library calls all have the prefix "pt_" to distinguish them from the pthreads calls they wrap.
They all have the form:
pt_xxx(object *obj,..., char *msg)The "object *" is always a pointer to a pthreads object (or one of the derived types discussed later). The "char *msg" is a message that is printed in case of an error. When errors occur, your code will exit. Since most pthreads routines only return the EINVAL error, this seems acceptable -- usually it means that you've attempted to operate on an invalid pointer. Let's use these macros to clean things up a bit -- the new code is called simple2.c (click here for simple2.c; click here for pt.h ): 1: /****************************************************************** 2: * simple2.c -- multithreaded "hello world" using pt_xxx macros 3: * 4: * Author: Mark Hays 5: */ 6: 7: #include "pt.h" 8: 9: #include 10: 11: #define NTHREADS 412: 13: /******** this is the thread code */14: pt_addr_t hola(pt_addr_t arg)
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




