On 2020-10-01 5:19 AM, Phil Smith III wrote:
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;
}




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 [email protected] with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to