Discussion:
usleep()
(too old to reply)
Phil Smith III
2020-09-30 21:19:44 UTC
Permalink
The usleep() function in z/OS is documented as taking a single operand that must be less than 1M; on other platforms, it must be *at least* 1M. It also generates no error, and just returns instantly if you give it a value of 1M or more.



This seems.poor. Anyone got any insight/guesses? Yes, I realize it's deprecated.



All I can think of is that when it was implemented in z/OS it was done deliberately to discourage use, but I'd rather it ABENDed than just returning instantly and causing a spin, personally.


----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Kirk Wolf
2020-09-30 21:40:25 UTC
Permalink
I don't believe so. Which other platforms?
https://man7.org/linux/man-pages/man3/usleep.3.html
Post by Phil Smith III
The usleep() function in z/OS is documented as taking a single operand
that must be less than 1M; on other platforms, it must be *at least* 1M. It
also generates no error, and just returns instantly if you give it a value
of 1M or more.
This seems.poor. Anyone got any insight/guesses? Yes, I realize it's deprecated.
All I can think of is that when it was implemented in z/OS it was done
deliberately to discourage use, but I'd rather it ABENDed than just
returning instantly and causing a spin, personally.
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Eric Rossman
2020-09-30 22:31:19 UTC
Permalink
I've never seen a platform where a value over 1M was permitted. (Every man page I can find has wording similar to "EINVAL usec is greater than or equal to 1000000. (On systems where that is considered an error.)"")

Whether it is deprecated or not, it is clearly a bug for it to fail to return -1 and set errno. The documentation (from 2.4) clearly states:
"The useconds argument must be less than 1,000,000. If the value of useconds is 0, then the call has no effect."
and
"EINVAL The useconds argument was greater than or equal to 1,000,000."

Eric
Post by Phil Smith III
The usleep() function in z/OS is documented as taking a single operand that must be less than 1M; on other platforms, it must be *at least* 1M. It also generates no error, and just returns instantly if you give it a value of 1M or more.
This seems.poor. Anyone got any insight/guesses? Yes, I realize it's deprecated.
All I can think of is that when it was implemented in z/OS it was done deliberately to discourage use, but I'd rather it ABENDed than just returning instantly and causing a spin, personally.
David Crayford
2020-10-01 08:13:06 UTC
Permalink
Post by Phil Smith III
The usleep() function in z/OS is documented as taking a single operand that must be less than 1M; on other platforms, it must be *at least* 1M. It also generates no error, and just returns instantly if you give it a value of 1M or more.
usleep() returns -1 and sets errno to EINVAL which is the usual C semantics.

FWIW, usleep() has been deprecated for nanosleep() on most UNIX-like
platforms. The z/OS C/C++ RTL does not provide nanosleep() but it's
trivial to roll your own.

#define CW_INTRPT    1

#define JRTIMEOUT   0x81F0211  // wait time exceeded

#ifdef _LP64
  #pragma map(cond_timed_wait, "BPX4CTW")
#else
  #pragma map(cond_timed_wait, "BPX1CTW")
#endif

#pragma linkage(cond_timed_wait,os)

void cond_timed_wait(
    int * seconds,
    int * nanoseconds,
    int * event_list,
    int * seconds_remaining,
    int * nanoseconds_remaining,
    int * return_value,
    int * return_code,
    int * reason_code
    );


int nanosleep(
    struct timespec * rqtp,
    struct timespec * rmtp
    )
{
    int return_value = 0;
    int return_code = 0;
    int reason_code = 0;
    struct timespec r = { 0, 0 };
    int event_list = CW_INTRPT;
    cond_timed_wait(
&rqtp->tv_sec,
&rqtp->tv_nsec,
        &event_list,
        &r.tv_sec,
        &r.tv_nsec,
        &return_value,
        &return_code,
        &reason_code
        );
    errno = return_code;
    if (return_code == EAGAIN && reason_code == JRTIMEOUT) {
        return_code = 0;
    }
    if (rmtp) {
        *rmtp = r;
    }
    return return_code;
}
Post by Phil Smith III
This seems.poor. Anyone got any insight/guesses? Yes, I realize it's deprecated.
All I can think of is that when it was implemented in z/OS it was done deliberately to discourage use, but I'd rather it ABENDed than just returning instantly and causing a spin, personally.
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Paul Gilmartin
2020-10-01 12:16:15 UTC
Permalink
Post by Phil Smith III
The usleep() function in z/OS is documented as taking a single operand that must be less than 1M; on other platforms, it must be *at least* 1M. It also generates no error, and just returns instantly if you give it a value of 1M or more.
This seems.poor. Anyone got any insight/guesses? Yes, I realize it's deprecated.
What is IBM's rationale for supporting the deprecated usleep but not
POSIX nanosleep on z/OS?
https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html#tag_16_350

And providing the idiosyncratic cond_timed_wait.

-- gil

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
David Crayford
2020-10-02 11:21:38 UTC
Permalink
Post by Paul Gilmartin
Post by Phil Smith III
The usleep() function in z/OS is documented as taking a single operand that must be less than 1M; on other platforms, it must be *at least* 1M. It also generates no error, and just returns instantly if you give it a value of 1M or more.
This seems.poor. Anyone got any insight/guesses? Yes, I realize it's deprecated.
What is IBM's rationale for supporting the deprecated usleep but not
POSIX nanosleep on z/OS?
https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html#tag_16_350
And providing the idiosyncratic cond_timed_wait.
Probably the same rationale for supporting System V message
queues/semaphores etc and not POSIX.
Post by Paul Gilmartin
-- gil
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Thomas David Rivers
2020-10-02 15:23:58 UTC
Permalink
Post by Paul Gilmartin
What is IBM's rationale for supporting the deprecated usleep but not
POSIX nanosleep on z/OS?
https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html#tag_16_350
And providing the idiosyncratic cond_timed_wait.
-- gil
We added nanosleep() to the Dignus runtime library, and as IBM's
documentation
suggests, it uses the BPX cond_timed_wait function (there's a note there
saying you
can use BPX cond_timed_wait to implement nanosleep.)

So - it would be pretty easy to add your own nanosleep if you want, just
call
cond_timed_wait as IBM says.

nanosleep() is "newer" than the original POSIX-1, so I suppose until
some customer
submits an RFE for it it won't appear in the IBM C library. It's also
part of the REALTIME
section of POSIX, which IBM doesn't support.


https://pubs.opengroup.org/onlinepubs/009695399/functions/nanosleep.html

z/OS doesn't really let you do the REALTIME timers (yet, I suppose), but
this function
is so handy and so common we added it to our runtime.

And, in fact, our usleep() just invokes nanosleep() as is now common on
many implementations.


- Dave R. -
--
***@dignus.com Work: (919) 676-0847
Get your mainframe programming tools at http://www.dignus.com
Mike Schwab
2020-10-02 15:55:12 UTC
Permalink
I think IBM did the minimum amount of work to qualify for the U.S.
Government requirement for POSIX at one point and has not kept it up
to date.
Post by Thomas David Rivers
Post by Paul Gilmartin
What is IBM's rationale for supporting the deprecated usleep but not
POSIX nanosleep on z/OS?
https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html#tag_16_350
And providing the idiosyncratic cond_timed_wait.
-- gil
We added nanosleep() to the Dignus runtime library, and as IBM's
documentation
suggests, it uses the BPX cond_timed_wait function (there's a note there
saying you
can use BPX cond_timed_wait to implement nanosleep.)
So - it would be pretty easy to add your own nanosleep if you want, just
call
cond_timed_wait as IBM says.
nanosleep() is "newer" than the original POSIX-1, so I suppose until
some customer
submits an RFE for it it won't appear in the IBM C library. It's also
part of the REALTIME
section of POSIX, which IBM doesn't support.
https://pubs.opengroup.org/onlinepubs/009695399/functions/nanosleep.html
z/OS doesn't really let you do the REALTIME timers (yet, I suppose), but
this function
is so handy and so common we added it to our runtime.
And, in fact, our usleep() just invokes nanosleep() as is now common on
many implementations.
- Dave R. -
--
Get your mainframe programming tools at http://www.dignus.com
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
--
Mike A Schwab, Springfield IL USA
Where do Forest Rangers go to get away from it all?

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Seymour J Metz
2020-10-02 15:59:46 UTC
Permalink
Not quite; they did the minimim amount for POSIX and X-Open, then added stuff for later iterations of their UNIX certification.


--
Shmuel (Seymour J.) Metz
http://mason.gmu.edu/~smetz3


________________________________________
From: IBM Mainframe Discussion List <IBM-***@LISTSERV.UA.EDU> on behalf of Mike Schwab <***@GMAIL.COM>
Sent: Friday, October 2, 2020 11:54 AM
To: IBM-***@LISTSERV.UA.EDU
Subject: Re: usleep()

I think IBM did the minimum amount of work to qualify for the U.S.
Government requirement for POSIX at one point and has not kept it up
to date.
Post by Thomas David Rivers
Post by Paul Gilmartin
What is IBM's rationale for supporting the deprecated usleep but not
POSIX nanosleep on z/OS?
https://secure-web.cisco.com/15ber4_2yl9qOXLoJC6r3enZh5QziAVC39L_snbERfZSOwZFHn-tPUvFtPPjNeP6J-fAnmc7zVBdb45A4VmZrFvek-ec24Rlfmw045YNkKgXTMLmr5bLh07-og-huGCRHRbDdSiEq0KHeu95pRw_Nk5k6VqEh7iFgeVdnMOVKrjkbH3X2-583UcfIup0vYE9qgWZznA0aqgyYuGxE76uNHIcgjLSDI-Sm_2ZyfY5JOwWKh2ZDZPgQxmhg6-zaXWWX0RjxdNgKR5XKOJV5_aNd-PF3vqd4TdiFW7wp6J-23m7-HOUy4XufdmPhSMiolqhEmRVWSjK6XgQnyO7etdCF72EngYc4lxoPDaR94QFZ0sGlyZgN6VtE_YQDiRyz7UHFStUPoXdhBLkZnSuA6tHxuIA22uSRaVO12GxNXZD-Z3hgI8X-842LAxp9Du7DCkQn/https%3A%2F%2Fpubs.opengroup.org%2Fonlinepubs%2F9699919799%2Ffunctions%2Fnanosleep.html#tag_16_350
And providing the idiosyncratic cond_timed_wait.
-- gil
We added nanosleep() to the Dignus runtime library, and as IBM's
documentation
suggests, it uses the BPX cond_timed_wait function (there's a note there
saying you
can use BPX cond_timed_wait to implement nanosleep.)
So - it would be pretty easy to add your own nanosleep if you want, just
call
cond_timed_wait as IBM says.
nanosleep() is "newer" than the original POSIX-1, so I suppose until
some customer
submits an RFE for it it won't appear in the IBM C library. It's also
part of the REALTIME
section of POSIX, which IBM doesn't support.
https://secure-web.cisco.com/1ta4flfdOYvdobDLBeabZZYwn_OUPyHpHl8NtZgg5L8XFEaQubjdtwe1iTgCUBB2pdY1dvJxnemRY9YA-pvr1EceoSF_itZ1yF2TyaMadI4ViFLY6qti_TQH1mfdxOvl_aL2Jknj2w5E1FM8C8fkjdPF-DmQG4ejsNjKuLjcGGz3wY3cclaWKw7bwGjN5t7CbJF9PXpj2KR82gutHMX7ljZQiBdssTeb4xSTdHM-iYpiDD3H5eXO5Yxs3J-KNztt8ofgaLN3dWzmcSrCd8cKsFVCYPd1aXrGBoFSscQZCUyZd91ZkuheKCZqqIqlveNAVgyht2UhSGdWWVEzFszXZkAROY77-kUYDoYQklmAJKyWZQ8OlDfz-L1wgiwn7JEFf5ZRxl819wrChSEpTZCyY70fRSbG_LHsSpOMvpFV8AtlAm6SUQlokHBao1SJeYY2y/https%3A%2F%2Fpubs.opengroup.org%2Fonlinepubs%2F009695399%2Ffunctions%2Fnanosleep.html
z/OS doesn't really let you do the REALTIME timers (yet, I suppose), but
this function
is so handy and so common we added it to our runtime.
And, in fact, our usleep() just invokes nanosleep() as is now common on
many implementations.
- Dave R. -
--
Get your mainframe programming tools at http://secure-web.cisco.com/1okrNzXX_qhM0bnfpYvmM6qzMIRH75unmneSRpkqyhHLC0fQt7-7dhfy-KnIxZtJb7jteOx1US9bej8vB83gWy66ln-9Dx-PfWwpmjnHvqG6Okgf_7bDzYZwIi8M98Wpnh3h5xz1M5Y0_Msz7d56lpBKUx1jEomTwF0A_7YogAu_vvYEhwyCDYFMoKHN4G1jGW74SI0aKSfjm7bV-JMbQhiCHJmCKlVbPRTeNJ1TJM6a1y1NOmCbOEeil4I2Il1vkSa1-Y6avocBqnjcDYEOZpEt8Agy6rOjDMco3WHBS0euKVXcKdYH5In5UV_S9YB5PSDZ2YCbd3SN78JP2524RW_Sa3CV4DTl0Y9cDSV3r2yxD69yPkS67qhc0-x2aqATIoXPVZLDsBRXzByw7-NzrrSJ7iKWIFqDucONIdqwpqBzq7lmMEhMXlZVdT1ytY1cV/http%3A%2F%2Fwww.dignus.com
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
--
Mike A Schwab, Springfield IL USA
Where do Forest Rangers go to get away from it all?

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN


----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Phil Smith III
2020-10-03 20:43:37 UTC
Permalink
Post by Kirk Wolf
I don't believe so. Which other platforms?
https://man7.org/linux/man-pages/man3/usleep.3.html
What he's referring to is that the phrase "usec is greater than or equal to 1000000" appears in an ERROR description. Somehow I missed that, reading it instead as a directive, although I swear that whatever man page I was looking at also said there were no errors from usleep()! (I will slightly defend myself by noting that the use of "is" rather than "was" isn't how I expect errors to be reported, though either is clearly reasonable.)



So."nevermind". And thanks, Kirk!



...phsiii




----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to ***@listserv.ua.edu with the message: INFO IBM-MAIN
Continue reading on narkive:
Loading...