zoukankan      html  css  js  c++  java
  • 《POSIX多线程程序设计》笔记(2)作者自己写的两个调试宏函数源码

    开始看前面几个“闹钟”代码时,没找到errors.h到底在哪儿,原来。。。

    #include <pthread.h>
    #include <stdio.h>
    #include <errno.h>
    #include <string.h>
    
    int main(int argc, char *argv[])
    {
        pthread_t thread;
        int status;
    
        /*自死锁示例:
         *      大多数情况下,未初始化的pthread_t变量是一个无效线程ID,调用线程回收函数能正常检查出错误原因;
                但也有可能未初始化的值是一个有效的ID,此时,这个线程就进入了自死锁了.*/
        status = pthread_join(thread, NULL);
        if (status != 0)
        {
            /*strerror:
             *      区别于perror当关注当前errno对应的信息到标准错误,
             *      strerror是指定一个errno,并返回错误字符串,没有重定向到标准设备.*/
            fprintf(stderr, "error %d: %s
    ", status, strerror(status));                                                                  
            return status;
        }   
        return 0;
    } 
    #ifndef __errors_h                                                                                                                    
    #define __errors_h
    
    #include <unistd.h>
    #include <errno.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #ifdef DEBUG
    #define DPRINTF(arg) printf arg
    #else
    #define DPRINTF(arg)
    #endif
    
    #define err_abort(code, text) do { 
        fprintf(stderr, "%s at "%s":%d: %s
    ", 
                text, __FILE__, __LINE__, strerror(code)); 
        abort(); 
        } while(0)
    #define errno_abort(text) do { 
        fprintf(stderr, "%s at "%s":%d: %s
    ", 
                text, __FILE__, __LINE__, strerror(errno)); 
        abort(); 
        } while(0)
    
    #endif
  • 相关阅读:
    命令基础
    绑定在表单验证上的应用
    绑定和绑定的各种使用场景
    双向数据绑定
    事件
    委托应用及泛型委托和多播委托
    委托
    LINQ
    反射重要属性方法
    反射基本内容
  • 原文地址:https://www.cnblogs.com/orejia/p/12555899.html
Copyright © 2011-2022 走看看