Hello Jeff,
Shouldn't we use pg_usleep to ensure portability? it is defined for
front-end code. But it returns void, so the error check will have to be
changed.
Attached v3 with pg_usleep called instead.
I didn't see the problem before the commit I originally indicated , so I
don't think it has to be back-patched to before v10.
Hmmm.... you've got a point, although I'm not sure how it could work
without sleeping explicitely. Maybe the path was calling select with an
empty wait list plus timeout, and select is kind enough to just sleep on
an empty list, or some other miracle. ISTM clearer to explicitely sleep in
that case.
--
Fabien.
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index e37496c..524fcc6 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -4582,20 +4582,30 @@ threadRun(void *arg)
* or it's time to print a progress report. Update input_mask to show
* which client(s) received data.
*/
- if (min_usec > 0 && maxsock != -1)
+ if (min_usec > 0)
{
- int nsocks; /* return from select(2) */
+ int nsocks = 0; /* return from select(2) if called */
if (min_usec != PG_INT64_MAX)
{
- struct timeval timeout;
+ if (maxsock != -1)
+ {
+ struct timeval timeout;
- timeout.tv_sec = min_usec / 1000000;
- timeout.tv_usec = min_usec % 1000000;
- nsocks = select(maxsock + 1, &input_mask, NULL, NULL, &timeout);
+ timeout.tv_sec = min_usec / 1000000;
+ timeout.tv_usec = min_usec % 1000000;
+ nsocks = select(maxsock + 1, &input_mask, NULL, NULL, &timeout);
+ }
+ else /* nothing active, simple sleep */
+ {
+ pg_usleep(min_usec);
+ }
}
- else
+ else /* no explicit delay, select without timeout */
+ {
nsocks = select(maxsock + 1, &input_mask, NULL, NULL, NULL);
+ }
+
if (nsocks < 0)
{
if (errno == EINTR)
@@ -4608,7 +4618,7 @@ threadRun(void *arg)
goto done;
}
}
- else
+ else /* min_usec == 0, i.e. something needs to be executed */
{
/* If we didn't call select(), don't try to read any data */
FD_ZERO(&input_mask);
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers