hello world
i try to do a simple pthread test on android (natively)
/*========START OF CODE ===============*/
#include <stdio.h>
#include <sys/types.h>
#include <pthread.h>
void *hello(void *arg)
{
printf("Hello from node %d\n", *(int *)arg);
}
int main(int argc, char* argv[])
{
int n,i;
pthread_t threads[2];
n = 2;
/* Start up thread */
for (i = 0; i < n; i++)
{
pthread_create(&threads[i], NULL, hello, (void *)&i);
}
/* Synchronize the completion of each thread. */
for (i = 0; i < n; i++)
{
pthread_join(threads[i],NULL);
}
printf("pthread_test returns \n");
return 0;
}
/*===========END OF CODE=========*/
then i compile it (pthread.c)
$>arm-none-linux-gnueabi-gcc -c -g pthread.c
$>arm-none-linux-gnueabi-ld --entry=main --dynamic-linker /system/bin/
linker -nostdlib -rpath /system/lib -rpath system/lib -L system/lib -
lc -o pthread_test pthread.o
./system is the directory of system image
but in pthread_join , SIGSEGV will be generated
i use strace to debug this
# ./strace ./pthread_test
execve("./pthread_test", ["./pthread_test"], [/* 10 vars */]) = 0
getpid() = 189
syscall_983045(0xb00169c4, 0x4990, 0xb0011030, 0, 0x1, 0xbecf6d94,
0xbecf6d9c, 0xf0005, 0, 0, 0, 0, 0, 0xbecf6d60, 0xb0000dcd,
0xb00015ac, 0x80000010, 0xb00169c4, 0, 0, 0, 0xeb48, 0xcd1f8, 0xcd1d0,
0, 0, 0, 0, 0, 0, 0, 0) = 0
gettid() = 189
sigaction(SIGILL, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
sigaction(SIGABRT, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
sigaction(SIGBUS, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
sigaction(SIGFPE, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
sigaction(SIGSEGV, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
sigaction(SIGSTKFLT, {0xb0001211, [], SA_RESTART}, {SIG_DFL}, 0) = 0
open("libc.so", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or
directory)
open("/system/lib/libc.so", O_RDONLY|O_LARGEFILE) = 3
lseek(3, 0, SEEK_SET) = 0
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0`
\225\0\000"..., 4096) = 4096
lseek(3, -8, SEEK_END) = 227472
read(3, "\0\0\340\257PRE ", 8) = 8
mmap2(0xafe00000, 274432, PROT_READ|PROT_EXEC, MAP_PRIVATE|
MAP_ANONYMOUS, -1, 0) = 0xafe00000
mmap2(0xafe00000, 214032, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED,
3, 0) = 0xafe00000
mprotect(0xafe00000, 217088, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
mmap2(0xafe35000, 8420, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED,
3, 0x35) = 0xafe35000
mmap2(0xafe38000, 41760, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|
MAP_ANONYMOUS, -1, 0) = 0xafe38000
close(3) = 0
mprotect(0xafe00000, 217088, PROT_READ|PROT_EXEC) = 0
getuid32() = 0
geteuid32() = 0
open("/dev/urandom", O_RDONLY|O_LARGEFILE) = 3
read(3, "%\374\353\364", 4) = 4
close(3) = 0
mprotect(0x8000, 4096, PROT_READ|PROT_EXEC) = 0
getuid32() = 0
geteuid32() = 0
brk(0) = 0x11000
brk(0x11000) = 0x11000
brk(0x12000) = 0x12000
mmap2(0x10000000, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|
MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x10000000
mprotect(0x10000000, 4096, PROT_NONE) = 0
clone(child_stack=0x100fff00, flags=CLONE_VM|CLONE_FS|CLONE_FILES|
CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_DETACHED) = 190
futex(0x100fff00, FUTEX_WAKE, 1Hello from node 0
) = 1
mmap2(0x10000000, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|
MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x10000000
mprotect(0x10000000, 4096, PROT_NONE) = 0
clone(child_stack=0x100fff00, flags=CLONE_VM|CLONE_FS|CLONE_FILES|
CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_DETACHED) = 191
futex(0x100fff00, FUTEX_WAKE, 1Hello from node 1
) = 1
--- SIGSEGV (Segmentation fault) @ 0 (4) ---
sigaction(SIGUSR1, {SIG_IGN}, {SIG_DFL}, 0) = 0
gettid() = 189
SYS_281(0x1, 0x1, 0, 0xffffe52c, 0xb000f55c) = 3
SYS_283(0x3, 0xbecf69b6, 0x14, 0x1, 0x3) = 0
write(3, "\275\0\0\0", 4) = 4
read(3, 0xbecf6a54, 1) = ? ERESTARTSYS (To be
restarted)
--- SIGCONT (Continued) @ 0 (0) ---
read(3, "", 1) = 0
close(3) = 0
sigaction(SIGSEGV, {SIG_IGN}, {0xb0001211, [], SA_RESTART}, 0) = 0
sigreturn() = ? (mask now [])
--- SIGSEGV (Segmentation fault) @ 0 (4) ---
+++ killed by SIGSEGV +++
so i would like to ask why pthread_join here will always generate
SIGSEGV???
thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---