VirtualBox

Changeset 2472 in kBuild for trunk/src/lib


Ignore:
Timestamp:
Jul 12, 2011 2:12:57 PM (14 years ago)
Author:
bird
Message:

2nd attempt at reproducing it...

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/test-eintr-bug-2.c

    r2471 r2472  
    44*   Header Files                                                               *
    55*******************************************************************************/
    6 #define _XOPEN_SOURCE
    76#define _BSD_SOURCE
     7#define _GNU_SOURCE
    88#include <sys/time.h>
    99#include <sys/stat.h>
     10#include <time.h>
    1011#include <stdio.h>
    11 #include <signal.h>
    1212#include <string.h>
    1313#include <errno.h>
     14#include <pthread.h>
     15#include <signal.h>
    1416
    1517
    16 static void SigAlaramHandler(int iSig)
     18/*******************************************************************************
     19*   Global Variables                                                           *
     20*******************************************************************************/
     21/** The number of signals. */
     22static volatile long    g_cSigs = 0;
     23/** Whether to shutdown or not. */
     24static volatile int     g_fShutdown = 0;
     25/** The handle of the main thread. */
     26static pthread_t        g_hMainThread;
     27
     28
     29static void SigHandler(int iSig)
    1730{
    18     /* ignore */
     31    g_cSigs++;
     32
    1933    (void)iSig;
     34}
     35
     36
     37static void NanoSleep(unsigned long cNanoSecs)
     38{
     39    struct timespec Ts;
     40    Ts.tv_sec  = 0;
     41    Ts.tv_nsec = cNanoSecs;
     42    nanosleep(&Ts, NULL);
     43}
     44
     45
     46static void *ThreadProc(void *pvIgnored)
     47{
     48    while (!g_fShutdown)
     49    {
     50        NanoSleep(850);
     51        if (g_fShutdown)
     52            break;
     53
     54        pthread_kill(g_hMainThread, SIGALRM);
     55    }
     56    return NULL;
    2057}
    2158
     
    2360int main(int argc, char **argv)
    2461{
    25     struct itimerval TmrVal;
    2662    void (*rcSig)(int);
     63    pthread_t hThread;
     64    char szName[1024];
    2765    int i;
    2866    int rc;
    2967
    3068    /*
    31      * Set up the timer signal.
     69     * Set up the signal handlers.
    3270     */
    33     rcSig = bsd_signal(SIGALRM, SigAlaramHandler);
     71    rcSig = bsd_signal(SIGALRM, SigHandler);
     72    if (rcSig != SIG_ERR)
     73        rcSig = bsd_signal(SIGCHLD, SigHandler);
    3474    if (rcSig == SIG_ERR)
    3575    {
     
    3878    }
    3979    if (argc == 2) /* testing... */
     80    {
    4081        siginterrupt(SIGALRM, 1);
     82        siginterrupt(SIGCHLD, 1);
     83    }
    4184
    42     memset(&TmrVal, '\0', sizeof(TmrVal));
    43     TmrVal.it_interval.tv_sec  = TmrVal.it_value.tv_sec  = 0;
    44     TmrVal.it_interval.tv_usec = TmrVal.it_value.tv_usec = 1000;
    45     rc = setitimer(ITIMER_REAL, &TmrVal, NULL);
     85    /*
     86     * Kick off a thread that will signal us like there was no tomorrow.
     87     */
     88    g_hMainThread = pthread_self();
     89    rc = pthread_create(&hThread, NULL, ThreadProc, NULL);
    4690    if (rc != 0)
    4791    {
    48         fprintf(stderr, "setitimer failed: %s\n", strerror(errno));
     92        fprintf(stderr, "pthread_create failed: %s\n", strerror(rc));
    4993        return 1;
    5094    }
     
    5397     * Do path related stuff.
    5498     */
     99    snprintf(szName, sizeof(szName), "%s-test2", argv[0]);
    55100    for (i = 0; i < 100*1000*1000; i++)
    56101    {
    57102        struct stat St;
     103
    58104        rc = stat(argv[0], &St);
    59         if (rc != 0)
     105        if (rc == 0 || errno != EINTR)
     106            rc = stat(szName, &St);
     107        if (errno == EINTR && rc != 0)
    60108        {
    61109            printf("iteration %d: stat: %u\n", i, errno);
    62110            break;
    63111        }
     112        if ((i % 100000) == 0)
     113        {
     114            printf(".");
     115            if ((i % 1000000) == 0)
     116                printf("[%d/%ld]", i, g_cSigs);
     117            fflush(stdout);
     118        }
    64119    }
    65120
     121    g_fShutdown = 1;
    66122    if (rc)
    67123        printf("No EINTR in %d iterations - system is working nicely!\n", i);
    68 
    69     TmrVal.it_interval.tv_sec  = TmrVal.it_value.tv_sec  = 0;
    70     TmrVal.it_interval.tv_usec = TmrVal.it_value.tv_usec = 0;
    71     setitimer(ITIMER_REAL, &TmrVal, NULL);
     124    NanoSleep(10000000);
    72125
    73126    return rc ? 1 : 0;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette