Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Message-ID: <3B7AC4B8.9EAD158B@sibbald.com> Date: Wed, 15 Aug 2001 20:51:36 +0200 From: Kern Sibbald X-Mailer: Mozilla 4.77 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: pthread_cond_timedwait() problem Content-Type: multipart/mixed; boundary="------------00E222E978A86D46BD143266" Note-from-DJ: This may be spam --------------00E222E978A86D46BD143266 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello, The attached program seems to work fine on Linux, but dies with a segmentation fault when compiled with Cygwin and run on Win98. To compile on Linux: cc xxx.c -o xxx -lpthread Output: each line is printed after a wait of 10 seconds: Timed out Second timedwait timed out To compile on Cygwin: gcc xxx.c -o xxx.exe Output: 0 [main] xxx 995963 open_stackdumpfile: Dumping stack trace to XXX.EXE.stackdump Segmentation fault (core dumped) I'm using: CYGWIN_98-4.10 MINIMATOU 1.3.2(0.39/3/2) 2001-05-20 23:28 i586 unknown I'm not subscribed to your list, so if you wish to respond, please include my email address. Any help making this program work would be appreciated. Best regards, Kern --------------00E222E978A86D46BD143266 Content-Type: image/x-xbitmap; name="xxx.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="xxx.c" #define _REENTRANT 1 #define _THREAD_SAFE 1 #include #include #include #include #include #include typedef struct workq_tag { pthread_mutex_t mutex; /* queue access control */ pthread_cond_t work; /* wait for work */ pthread_attr_t attr; /* create detached threads */ int valid; /* queue initialized */ int quit; /* workq should quit */ int max_workers; /* max threads */ int num_workers; /* current threads */ int idle_workers; /* idle threads */ void (*engine)(void *arg); /* user engine */ } workq_t; int main() { struct timespec to; workq_t *wq; int stat; struct timeval tv; struct timezone tz; wq = malloc(sizeof(workq_t)); memset(wq, 0, sizeof(workq_t)); if ((stat = pthread_mutex_init(&wq->mutex, NULL)) != 0) { return 1; } if ((stat = pthread_cond_init(&wq->work, NULL)) != 0) { pthread_mutex_destroy(&wq->mutex); return 1; } if ((stat = pthread_mutex_lock(&wq->mutex)) != 0) { return 1; } gettimeofday(&tv, &tz); to.tv_nsec = 0; to.tv_sec = tv.tv_sec + 10; stat = pthread_cond_timedwait(&wq->work, &wq->mutex, &to); if (stat == ETIMEDOUT) { printf("Timed out\n"); } else if (stat != 0) { printf("pthread_cond_timedwait error.\n"); pthread_mutex_unlock(&wq->mutex); return 1; } pthread_mutex_unlock(&wq->mutex); gettimeofday(&tv, &tz); to.tv_nsec = 0; to.tv_sec = tv.tv_sec + 10; stat = pthread_cond_timedwait(&wq->work, &wq->mutex, &to); if (stat == ETIMEDOUT) { printf("Second timedwait timed out\n"); } else if (stat != 0) { printf("pthread_cond_timedwait error.\n"); pthread_mutex_unlock(&wq->mutex); return 1; } return 0; } --------------00E222E978A86D46BD143266 Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ --------------00E222E978A86D46BD143266--