Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bus error #9

Open
damon-kwok opened this issue Jul 10, 2018 · 2 comments
Open

Bus error #9

damon-kwok opened this issue Jul 10, 2018 · 2 comments

Comments

@damon-kwok
Copy link

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.out

output:
123456
123456
123456
123456
123456
Bus error

@skeeto
Copy link
Owner

skeeto commented Jul 10, 2018 via email

@damon-kwok
Copy link
Author

damon-kwok commented Jul 12, 2018

x86-64
void *ret=NULL, *ret2=NULL;
now, it's ok, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants