Mail Archives: cygwin/2001/08/15/14:52:18
--------------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 <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <errno.h>
#include <pthread.h>
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--
- Raw text -