c - Why is this code blocking? -
i have code takes short while complete. i'd handled on separate thread blocked io. implemented following, when calling thread runs background_picture_save()
, seems block. why?
i'm trying save_picture()
function work background process.
static void * threaded_save_picture(void * p); static void * threaded_save_picture(void * p) { char optarg[512]; strncpy(optarg, p, sizeof optarg); optarg[sizeof optarg - 1] = '\0'; fprintf(stderr,"%s()::%s\n",__function__,optarg); save_picture(optarg); pthread_detach(pthread_self()); return(p); } /* threaded_save_picture() */ extern void background_picture_save(const char * const optarg); void background_picture_save(const char * const optarg) { pthread_t thrd; (void)pthread_create(& thrd, null, threaded_save_picture, (void *) optarg); } /* background_picture_save() */
take ambiguity out of observations.
run program gdb, when main thread blocks print backtrace "where".
use strace show system calls being made when blocking.
use systemtap http://sourceware.org/systemtap/ show kernel backtraces blocked process (although see pthreads support went in http://www.cygwin.com/ml/libc-alpha/2011-01/threads.html#00010).
Comments
Post a Comment