/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#include <ssdef.h>
#include <starlet.h>
#include <lib$routines.h>

static int32_t counter;

void incr(int64_t arg)
{
    counter++;
}

static const int64_t ZERO = 0;
static const int32_t N = 1000000;

int main(int argc, char *argv[])
{
    int32_t stat, i;
    int64_t t1, t2;
    counter = 0;
    stat = sys$gettim(&t1, 0);
    if(stat != SS$_NORMAL) lib$signal(stat);
    for(i = 0; i < N; i++)
    {
        stat = sys$setimr(0, &ZERO, incr, 0, 0);
        if(stat != SS$_NORMAL) lib$signal(stat);
    }
    while(counter < N) 
    {
        sleep(0);
    }
    stat = sys$gettim(&t2, 0);
    if(stat != SS$_NORMAL) lib$signal(stat);
    printf("counter incr = %d in %lld ns (%lld AST/sec)\n", counter, (t2 - t1) * 100, counter * 10000000LL / (t2 - t1));
    return 0;
}

