zoukankan      html  css  js  c++  java
  • c assert函数

    条件为false,调用abort函数退出进程,在线程中执行也会导致进程退出

    //
    // Created by gxf on 2020/3/8.
    //
    #include "linklist.h"
    #include <assert.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <pthread.h>
    #include <unistd.h>
    
    void printHello();
    
    int main() {
        int a = 1;
        int b = 0;
        pthread_t thread;
    
        pthread_create(&thread, NULL, printHello, NULL);
    
        pthread_join(thread, NULL);
    
        printf("before abort
    ");
        abort();
        assert(b < a);
        printf("hello assert
    ");
    
    
        return 0;
    }
    
    void printHello() {
        int k = 1000;
        int i = 0;
        while (1) {
            if (i == 10) {
                assert(k < i);
            }
            i ++;
            printf("hello
    ");
            sleep(1);
        }
    }
    

      

  • 相关阅读:
    Angular(一)
    多变的形状
    二叉树
    快速排序
    冒泡排序
    插入排序
    大话程序猿眼里的高并发架构
    整屏滚动
    增加删除一行标签
    无缝滚动
  • 原文地址:https://www.cnblogs.com/luckygxf/p/12441409.html
Copyright © 2011-2022 走看看