-
Notifications
You must be signed in to change notification settings - Fork 28
Description
OS: Ubuntu 16.04
GCC:5.5.0 20171010
main.c:
`
#include "lstack.h"
#include <pthread.h>
#include <stdio.h>
lstack_t *ff;
int aaa = 0;
int bbb = 0;
void *thread_fn(void *arg) {
for (int i = 0; i < 100; i++) {
lstack_push(ff, "123456");
aaa++;
}
return ((void *)0);
}
void *thread_fn2(void *arg) {
for (int i = 0; i < 100; i++) {
void *data = lstack_pop(ff);
if(data==NULL)
continue;
printf("%s\n", (char *)data);
bbb++;
}
return ((void *)0);
}
int main(int argc, char *argv[]) {
lstack_t s;
lstack_init(&s, 200);
ff = &s;
pthread_t ntid, ntid2;
pthread_create(&ntid, NULL, thread_fn, NULL);
pthread_create(&ntid2, NULL, thread_fn2, NULL);
void *ret, *ret2;
pthread_join(ntid, ret);
pthread_join(ntid2, ret2);
printf("aaa=%d,bbb=%d\n", aaa, bbb);
return 0;
}
`
gcc main.c lstack.c -latomic -lpthread
./a.outoutput:
123456
123456
123456
123456
123456
Bus error