C - pthread_create - Clang GCC difference -
passing argument pthread_create clang (3.6.1) , gcc (5.1.0) brings different results strange case, illustrated here:
pthread_t spawn_bserver_thread(uint16_t portno) { pthread_t tid; int32_t sockfd = create_bserver(portno); set_nonblocking(sockfd); exit_ncurses(); printf("%d\n", sockfd); if(pthread_create(&tid, null, bserver_thread, &sockfd) != 0) error("pthread_create"); return tid; } and bserver_thread:
static void * bserver_thread(void *arg) { printf("%d\n", *(int32_t*)arg); exit(1); ... } with gcc prints same number, not clang. (my typical result 4 , 4 gcc 4 32767 clang). doing wrong here?
here cflags if can change anything: -wall -wextra -ggdb
the problem have no control on when thread starts run, spawn_bserver_thread function may exit before thread function starts, meaning sockfd variable goes out of scope , pointer argument bserver_thread function no longer valid.
Comments
Post a Comment