curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl_multi_perform sometimes does not return while its threadus es1 00% cpu resources

From: <h9791521_at_docomo.ne.jp>
Date: Tue, 8 Jan 2019 20:39:35 +0900

Hello

Thanks to the suggestion I received, I finally fixed the problem.

 timediff_t Curl_timediff(struct curltime newer, struct curltime older)
 {
- timediff_t diff = newer.tv_sec-older.tv_sec;
+ timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec

This code apsolutely worked well, no endless loop any more.

The cast has higher precedence than the addition, so this would end up
signed subtracting unsigned resulting unsigned, I think.
Is my understanding wrong?

Should I simply modify like this?

timediff_t diff = (timediff_t)newer.tv_sec-(timediff_t)older.tv_sec

Maybe I’m wrong since the suggested code worked absolutely well.

Best regards



差出人: Daniel Stenberg<daniel_at_haxx.se>
日時: 2018年12月25日 19:14:47 JST
宛先:"h9791521_at_docomo.ne.jp"<h9791521_at_docomo.ne.jp>
Cc: libcurl development<curl-library_at_cool.haxx.se>
件名: Re: curl_multi_perform sometimes does not return while its threaduses1 00% cpu resources

> On Tue, 25 Dec 2018, "h9791521_at_docomo.ne.jp" wrote:
>
In reality, time_t is defined to unsigned type in 32 bit Windows

I'm still not convinced about this as it contradicts other sources, including
Microsoft's own documentation. Can you show us the exact typedefs used for
this and tell us which header file that makes that time_t type?

timediff_t Curl_timediff(struct curltime newer, struct curltime older)

This function is unit-tested in test 1323, also on Windows [1]. Wouldn't that
test fail if your claim is correct?

The Curl_timediff*() functions possibly need something like the patch below to
work with unsigned time_t:

diff --git a/lib/timeval.c b/lib/timeval.c
index 2d7c782fa..c8eff5a5b 100644
--- a/lib/timeval.c
+++ b/lib/timeval.c
@@ -185,26 +185,26 @@ struct curltime Curl_now(void)
  *
  * @unittest: 1323
  */
 timediff_t Curl_timediff(struct curltime newer, struct curltime older)
 {
- timediff_t diff = newer.tv_sec-older.tv_sec;
+ timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec;
   if(diff >= (TIME_MAX/1000))
     return TIME_MAX;
   else if(diff <= (TIME_MIN/1000))
     return TIME_MIN;
- return diff * 1000 + (newer.tv_usec-older.tv_usec)/1000;
+ return diff * 1000 + ((timediff_t)newer.tv_usec-older.tv_usec)/1000;
 }

 /*
  * Returns: time difference in number of microseconds. For too large diffs it
  * returns max value.
  */
 timediff_t Curl_timediff_us(struct curltime newer, struct curltime older)
 {
- timediff_t diff = newer.tv_sec-older.tv_sec;
+ timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec;
   if(diff >= (TIME_MAX/1000000))
     return TIME_MAX;
   else if(diff <= (TIME_MIN/1000000))
     return TIME_MIN;
- return diff * 1000000 + newer.tv_usec-older.tv_usec;
+ return diff * 1000000 + (timediff_t)newer.tv_usec-older.tv_usec;
 }




[1] =
https://ci.appveyor.com/project/curlorg/curl/builds/21046798/job/i6s5hasky0h5yt11#L8646

--

 / daniel.haxx.se

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2019-01-08