Subj : Re: returning arguments To : comp.programming.threads From : Huub Date : Tue Jun 28 2005 06:14 pm David Butenhof wrote: > Torsten Robitzki wrote: > >> Huub wrote: >> >>> Is it possible to return more than 1 value from a thread? >> >> >> Sure, just use a struct to return what ever you want to. > > > To (perhaps) make this more clear... technically, there's exactly ONE > return value from a thread. But the TYPE of that value is "void*" > (pointer). You can carry any pointer type in that "void* container". On > most contemporary mainstream systems you can get away with carrying any > scalar type x with sizeof(x) <= sizeof(void*). > > However, it's easy enough to malloc a structure and return a pointer to > that structure. The joiner can free the storage later. > Is the right way to do it? struct displaygegevens { int gasstatus; int rookstatus; int temperatuur; }; void *LeesSensoren(void *threadid) { ... try { ... displaygegevens = {gasstatus, rookstatus, temperatuur}; return (void*)displaygegevens; } catch(..) { } } void x() { try { int retv; void *retp; rc = pthread_create(...); pthread_exit(NULL); rc = pthread_join(.....); assert (rc == 0); return(retv = (int)retp); } catch (..) { } } } .