Circular lock-free buffer

后端 未结 18 723
悲哀的现实
悲哀的现实 2020-11-29 15:00

I\'m in the process of designing a system which connects to one or more stream of data feeds and do some analysis on the data than trigger events based on the result. In a t

18条回答
  •  野性不改
    2020-11-29 15:33

    You may try lfqueue

    It is simple to use, it is circular design lock free

    int *ret;
    
    lfqueue_t results;
    
    lfqueue_init(&results);
    
    /** Wrap This scope in multithread testing **/
    int_data = (int*) malloc(sizeof(int));
    assert(int_data != NULL);
    *int_data = i++;
    /*Enqueue*/
    while (lfqueue_enq(&results, int_data) != 1) ;
    
    /*Dequeue*/
    while ( (ret = lfqueue_deq(&results)) == NULL);
    
    // printf("%d\n", *(int*) ret );
    free(ret);
    /** End **/
    
    lfqueue_clear(&results);
    

提交回复
热议问题