Thread: [Quickfix-developers] process_sleep has unitialized pointer
Brought to you by:
orenmnero
From: Clark S. <cla...@ya...> - 2004-06-22 00:25:51
|
The pointer timespeck hasn't been initialized. Is this perhaps the cause of random wierdness? void process_sleep( double s ) { QF_STACK_PUSH(process_sleep) #ifdef _MSC_VER Sleep( ( long ) s * 1000 ); #else /* this causes random wierdness under Solaris timespec time; double intpart; time.tv_nsec = (int)modf(s, &intpart); time.tv_nsec *= 1000000000; time.tv_sec = (int)intpart; timespec* actual; nanosleep(&time, actual);*/ sleep( ( long ) s ); #endif QF_STACK_POP } I think this would work better: void process_sleep( double s ) { QF_STACK_PUSH(process_sleep) #ifdef _MSC_VER Sleep( ( long ) s * 1000 ); #else timespec time, actual; double intpart; time.tv_nsec = (int)modf(s, &intpart); time.tv_nsec *= 1000000000; time.tv_sec = (int)intpart; nanosleep(&time, &actual); sleep( ( long ) s ); #endif QF_STACK_POP } --------------------------------- Do you Yahoo!? Yahoo! Mail is new and improved - Check it out! |
From: Oren M. <or...@qu...> - 2004-06-22 00:52:13
|
Yeah, this makes sense. --oren On Jun 21, 2004, at 7:25 PM, Clark Sims wrote: > The pointer timespeck hasn't been initialized. Is this perhaps the=20 > cause of random wierdness? > > =A0 > > void process_sleep( double s ) > { QF_STACK_PUSH(process_sleep) > > #ifdef _MSC_VER > =A0=A0=A0 Sleep( ( long ) s * 1000 ); > #else > /* this causes random wierdness under Solaris > =A0 timespec time; > =A0 double intpart; > =A0 time.tv_nsec =3D (int)modf(s, &intpart); > =A0 time.tv_nsec *=3D 1000000000; > =A0 time.tv_sec =3D (int)intpart; > =A0 timespec* actual; > =A0 nanosleep(&time, actual);*/ > =A0sleep( ( long ) s ); > #endif > > =A0 QF_STACK_POP > } > > =A0 > > I think this would work better: > > > void process_sleep( double s ) > { QF_STACK_PUSH(process_sleep) > > #ifdef _MSC_VER > =A0=A0=A0 Sleep( ( long ) s * 1000 ); > #else > =A0 timespec time, actual; > =A0 double intpart; > =A0 time.tv_nsec =3D (int)modf(s, &intpart); > =A0 time.tv_nsec *=3D 1000000000; > =A0 time.tv_sec =3D (int)intpart; > =A0=A0 nanosleep(&time, &actual); > =A0sleep( ( long ) s ); > #endif > > =A0 QF_STACK_POP > } > > > Do you Yahoo!? > Yahoo! Mail is new and improved - Check it out!= |
From: Oren M. <or...@qu...> - 2004-06-22 01:01:22
|
Actually, if we aren't making use of that parameter, we can just use=20 NULL. The only time that the structure is written out if a signal has=20= been delivered to the process, thus interrupting the call and allowing=20= us to continue with the remainder. I don't think this is a situation=20 we need to really concern ourselves with, and it certainly isn't=20 handling this case right now. If the structure is set to NULL, the=20 system call will not try to write to the structure. So perhaps we=20 should just change the method to the following. void process_sleep( double s ) { QF_STACK_PUSH(process_sleep) #ifdef _MSC_VER Sleep( ( long ) s * 1000 ); #else timespec time; double intpart; time.tv_nsec =3D (int)modf(s, &intpart); time.tv_nsec *=3D 1000000000; time.tv_sec =3D (int)intpart; nanosleep(&time, NULL); #endif QF_STACK_POP } On Jun 21, 2004, at 7:25 PM, Clark Sims wrote: > The pointer timespeck hasn't been initialized. Is this perhaps the=20 > cause of random wierdness? > > =A0 > > void process_sleep( double s ) > { QF_STACK_PUSH(process_sleep) > > #ifdef _MSC_VER > =A0=A0=A0 Sleep( ( long ) s * 1000 ); > #else > /* this causes random wierdness under Solaris > =A0 timespec time; > =A0 double intpart; > =A0 time.tv_nsec =3D (int)modf(s, &intpart); > =A0 time.tv_nsec *=3D 1000000000; > =A0 time.tv_sec =3D (int)intpart; > =A0 timespec* actual; > =A0 nanosleep(&time, actual);*/ > =A0sleep( ( long ) s ); > #endif > > =A0 QF_STACK_POP > } > > =A0 > > I think this would work better: > > > void process_sleep( double s ) > { QF_STACK_PUSH(process_sleep) > > #ifdef _MSC_VER > =A0=A0=A0 Sleep( ( long ) s * 1000 ); > #else > =A0 timespec time, actual; > =A0 double intpart; > =A0 time.tv_nsec =3D (int)modf(s, &intpart); > =A0 time.tv_nsec *=3D 1000000000; > =A0 time.tv_sec =3D (int)intpart; > =A0=A0 nanosleep(&time, &actual); > =A0sleep( ( long ) s ); > #endif > > =A0 QF_STACK_POP > } > > > Do you Yahoo!? > Yahoo! Mail is new and improved - Check it out!= |
From: Joerg T. <Joe...@ma...> - 2004-06-22 08:33:12
|
Oren Miller wrote: > Actually, if we aren't making use of that parameter, we can just use > NULL. The only time that the structure is written out if a signal has > been delivered to the process, thus interrupting the call and allowing > us to continue with the remainder. I don't think this is a situation we > need to really concern ourselves with, and it certainly isn't handling > this case right now. I would suggest to do it right now. nanosleep() is the POSIX compliant way to wait and it is designed to make restarts after a signal easy: while( -1 == nanosleep( &time_to_sleep, &remainder ) ) { time_to_sleep = remainder; } > If the structure is set to NULL, the system call > will not try to write to the structure. So perhaps we should just change > the method to the following. > > void process_sleep( double s ) > { QF_STACK_PUSH(process_sleep) > > #ifdef _MSC_VER > Sleep( ( long ) s * 1000 ); > #else > timespec time; timespec time, remainder; > double intpart; > time.tv_nsec = (int)modf(s, &intpart); > time.tv_nsec *= 1000000000; Am I stupid? If I cast the fractional part returned from modf() to int, wouldn't it get 0? I would expect something like: time.tv_nsec = (long) ((modf(s, &intpart) * 1e6); > time.tv_sec = (int)intpart; time.tv_sec = (time_t) intpart; > nanosleep(&time, NULL); while ( -1 == nanosleep( &time, &remainder ) ) { time = remainder; } > #endif > > QF_STACK_POP > } -- Joerg Thoennes http://macd.com Tel.: +49 (0)241 44597-24 Macdonald Associates GmbH Fax : +49 (0)241 44597-10 Lothringer Str. 52, D-52070 Aachen |
From: Oren M. <or...@qu...> - 2004-06-22 11:32:53
|
Yeah, but I think it should be, time.tv_nsec = (long) ((modf(s, &intpart) * 1e9);, as a nanosecond is a billionth of a second. --oren On Jun 22, 2004, at 3:33 AM, Joerg Thoennes wrote: > Oren Miller wrote: >> Actually, if we aren't making use of that parameter, we can just use >> NULL. The only time that the structure is written out if a signal has >> been delivered to the process, thus interrupting the call and >> allowing us to continue with the remainder. I don't think this is a >> situation we need to really concern ourselves with, and it certainly >> isn't handling this case right now. > > I would suggest to do it right now. nanosleep() is the POSIX compliant > way to wait and it is designed to make restarts after a signal easy: > > while( -1 == nanosleep( &time_to_sleep, &remainder ) ) { > time_to_sleep = remainder; > } > >> If the structure is set to NULL, the system call will not try to >> write to the structure. So perhaps we should just change the method >> to the following. >> void process_sleep( double s ) >> { QF_STACK_PUSH(process_sleep) >> #ifdef _MSC_VER >> Sleep( ( long ) s * 1000 ); >> #else >> timespec time; > > timespec time, remainder; > >> double intpart; >> time.tv_nsec = (int)modf(s, &intpart); >> time.tv_nsec *= 1000000000; > > Am I stupid? If I cast the fractional part returned from modf() to > int, wouldn't it get 0? I would expect something like: > > time.tv_nsec = (long) ((modf(s, &intpart) * 1e6); > >> time.tv_sec = (int)intpart; > > time.tv_sec = (time_t) intpart; > >> nanosleep(&time, NULL); > > while ( -1 == nanosleep( &time, &remainder ) ) { > time = remainder; > } > >> #endif >> QF_STACK_POP >> } > > -- > Joerg Thoennes > http://macd.com > Tel.: +49 (0)241 44597-24 Macdonald Associates GmbH > Fax : +49 (0)241 44597-10 Lothringer Str. 52, D-52070 Aachen > |
From: Joerg T. <Joe...@ma...> - 2004-06-22 11:38:16
|
Oren Miller wrote: > Yeah, but I think it should be, time.tv_nsec = (long) ((modf(s, > &intpart) * 1e9);, as a nanosecond is a billionth of a second. OK, stupid mistake :-( Will you do the checkin? Thanks, Jörg > --oren > > On Jun 22, 2004, at 3:33 AM, Joerg Thoennes wrote: > >> Oren Miller wrote: >> >>> Actually, if we aren't making use of that parameter, we can just use >>> NULL. The only time that the structure is written out if a signal has >>> been delivered to the process, thus interrupting the call and >>> allowing us to continue with the remainder. I don't think this is a >>> situation we need to really concern ourselves with, and it certainly >>> isn't handling this case right now. >> >> >> I would suggest to do it right now. nanosleep() is the POSIX compliant >> way to wait and it is designed to make restarts after a signal easy: >> >> while( -1 == nanosleep( &time_to_sleep, &remainder ) ) { >> time_to_sleep = remainder; >> } >> >>> If the structure is set to NULL, the system call will not try to >>> write to the structure. So perhaps we should just change the method >>> to the following. >>> void process_sleep( double s ) >>> { QF_STACK_PUSH(process_sleep) >>> #ifdef _MSC_VER >>> Sleep( ( long ) s * 1000 ); >>> #else >>> timespec time; >> >> >> timespec time, remainder; >> >>> double intpart; >>> time.tv_nsec = (int)modf(s, &intpart); >>> time.tv_nsec *= 1000000000; >> >> >> Am I stupid? If I cast the fractional part returned from modf() to >> int, wouldn't it get 0? I would expect something like: >> >> time.tv_nsec = (long) ((modf(s, &intpart) * 1e6); >> >>> time.tv_sec = (int)intpart; >> >> >> time.tv_sec = (time_t) intpart; >> >>> nanosleep(&time, NULL); >> >> >> while ( -1 == nanosleep( &time, &remainder ) ) { >> time = remainder; >> } >> >>> #endif >>> QF_STACK_POP >>> } >> >> >> -- >> Joerg Thoennes >> http://macd.com >> Tel.: +49 (0)241 44597-24 Macdonald Associates GmbH >> Fax : +49 (0)241 44597-10 Lothringer Str. 52, D-52070 Aachen >> > > -- Joerg Thoennes http://macd.com Tel.: +49 (0)241 44597-24 Macdonald Associates GmbH Fax : +49 (0)241 44597-10 Lothringer Str. 52, D-52070 Aachen |