lock-free LIFO stack by C native built it, easy built cross platform(no extra dependencies needed) , guarantee thread safety memory management ever!
extern int lfstack_init(lfstack_t *lfstack);
extern int lfstack_push(lfstack_t *lfstack, void *value);
extern void* lfstack_pop(lfstack_t *lfstack);
extern void* lfstack_single_pop(lfstack_t *lfstack);
extern void lfstack_destroy(lfstack_t *lfstack);
extern size_t lfstack_size(lfstack_t *lfstack);
extern void lfstack_sleep(unsigned int milisec);
int* int_data;
lfstack_t mystack;
if (lfstack_init(&mystack) == -1)
return -1;
/** Wrap This scope in other threads **/
int_data = (int*) malloc(sizeof(int));
assert(int_data != NULL);
*int_data = i++;
/*PUSH*/
while (lfstack_push(&mystack, int_data) == -1) {
printf("ENQ Full ?\n");
}
/** Wrap This scope in other threads **/
/*POP*/
while ( (int_data = lfstack_pop(&mystack)) == NULL) {
printf("POP EMPTY ..\n");
}
// printf("%d\n", *(int*) int_data );
free(int_data);
/** End **/
lfstack_destroy(&mystack);
For linux OS, you may use cmake build, for other platforms, please kindly include the source code and header file into the project, e.g. VS2017, DEV-C++, Xcode
mkdir build
cd build
cmake ..
make
./lfstack-example
valgrind --tool=memcheck --leak-check=full ./lfstack-example
sudo make install
For continuously test until N number, if you having any issue while testing, please kindly raise an issue
./keep-testing.sh
cd build
sudo make uninstall