On 03/06/2013 09:04 PM, [email protected] wrote: > Hi! >> Add error checks to: >> >> Make sure this case not slip into one situation that >> the first pthread_once fails, and the second successes, >> then the case passes with bypassing its assertion. >> >> Give more detailed and exact execute result. > > Out of curiosity, have you seen the situation where the pthread_once() > has failed, or is this fix for a hypotetical condition (which is not > wrong at all)?
Ahh,as you mentioned. Actually,I did try to make pthread_once fail by initting "once_control" with invalid value,giving NULL as "init_routine" ,and so on,but it did not work at all. And,I scanned implementing of pthread_once in glibc src to find it nerver returns any other value than 0. So,it's maybe a "fix for a hypothetical condition" to follow POSIX. > >> Signed-off-by: DAN LI <[email protected]> >> --- >> .../conformance/interfaces/pthread_once/1-1.c | 17 >> +++++++++++++---- >> 1 file changed, 13 insertions(+), 4 deletions(-) >> >> diff --git >> a/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c >> b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c >> index 3a7c861..3392e6b 100644 >> --- >> a/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c >> +++ >> b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/1-1.c >> @@ -26,7 +26,7 @@ >> #include "posixtest.h" >> >> /* Keeps track of how many times the init function has been called. */ >> -int init_flag; >> +static int init_flag; >> >> /* The init function that pthread_once calls */ >> void *an_init_func() >> @@ -37,16 +37,25 @@ void *an_init_func() >> >> int main() >> { >> + int ret; >> + >> pthread_once_t once_control = PTHREAD_ONCE_INIT; >> >> init_flag = 0; >> >> /* Call pthread_once, passing it the once_control */ >> - pthread_once(&once_control, (void *)an_init_func); >> - >> + ret = pthread_once(&once_control, (void *)an_init_func); > > Hmm, I think that we can get rid the cast to the (void *) here. My gues > is that the function has wrong prototype which generates warning here. > > Accordingly to manual page it should be void (*init_routine)(void). So > the correct prototype should be void an_init_func(void). Could you > please fix the prototype and remove the (void *) casts as well? > Ok, thanks for reviewing. >> + if (ret != 0) { >> + printf("pthread_once failed\n"); >> + return PTS_UNRESOLVED; >> + } >> /* Call pthread_once again. The init function should not be >> * called. */ >> - pthread_once(&once_control, (void *)an_init_func); >> + ret = pthread_once(&once_control, (void *)an_init_func); >> + if (ret != 0) { >> + printf("pthread_once failed\n"); >> + return PTS_UNRESOLVED; >> + } >> >> if (init_flag != 1) { >> printf("Test FAILED\n"); > ------------------------------------------------------------------------------ Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the endpoint security space. For insight on selecting the right partner to tackle endpoint security challenges, access the full report. http://p.sf.net/sfu/symantec-dev2dev _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
