This is the mail archive of the mailing list for the pthreas-win32 project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

mingw and pthreads help !


I am trying to compile an example c-program using pthread rwlocks on
Windows, using mingw gcc-2.95.2, the crtdll version (the msvcrt version
gives me the exact same problem). When I finish compiling, after some
warnings, and try to execute the .exe file, I get a popup error window
which says the "gcc.dll" file could not be found (this only happens with
the pthreads program -- a simple hello-world program compiles and executes

Also, if I don't define _MSC_VER I get a parse error when including

Can anyone please help me figure out what I'm doing wrong ?



PS. Here's what I've done:

I've unpacked all the pthread-w32 dll's, libraries, and include files into
a directory named c:\pthrw32, which is also added to the path of the shell
program used to start mingw (mingw32.bat):

	REM ...<snip>
	REM add pthread dll directory to path variable

	REM start shell

This is what I did in the resulting command window on Win2K:

	E:\home\threads>gcc -D_REENTRANT -D_MSC_VER -O -Wall
-o thrtst thrtst.c -lpthreadw32 -Ic:\pthrw32 -Lc:\pthrw32
	In file included from thrtst.c:14:
	c:\pthrw32\pthread.h:1019: warning: `__except' redefined
\..\..\..\i386-mingw32\include\excpt.h:9: warning: this is the location
of the previous definition

	In file included from thrtst.c:14:
	c:\pthrw32\pthread.h:204: warning: ignoring pragma: )
	In file included from thrtst.c:14:
	c:\pthrw32\pthread.h:284: warning: ignoring pragma: )


	< popup window with message saying that gcc.dll could not be found >

Here is the silly pthread_rwlock example I'm trying to compile:

 *  thrtst.c
 *  How to compile:
 *  On Solaris:
 *  gcc  -D_REENTRANT -DSOL_SETCONC=4 -O -Wall -o thrtst thrtst.c -lpthread
 *  On Linux:
 *  gcc  -D_REENTRANT -D_XOPEN_SOURCE=500 -O -Wall -o thrtst thrtst.c -lpthread
 *  On Windows (mingw32 - gcc-2.95.2-crtdll):
 *  gcc  -D_REENTRANT -D_MSC_VER -O -Wall -o thrtst thrtst.c -lpthreadw32 \
 *  -Ic:\pthrw32 -Lc:\pthrw32

#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

pthread_rwlock_t rwlock;

void *reader( void *arg ) {

  unsigned long int i;

  pthread_rwlock_rdlock( &rwlock );
  fprintf( stderr, "--> %s starting to read\n", (char *)arg );

  for( i = 0; i < 50000000; ++i );	/* reading delay */

  fprintf( stderr, "<-- %s done reading\n", (char *)arg );
  pthread_rwlock_unlock( &rwlock );

  return NULL;

} /* reader */

void *writer( void *arg ) {

  unsigned long int i;

  pthread_rwlock_wrlock( &rwlock );
  fprintf( stderr, "==> %s starting to write\n", (char *)arg );

  for( i = 0; i < 50000000; ++i );	/* writing delay */

  fprintf( stderr, "<== %s done writing\n", (char *)arg );
  pthread_rwlock_unlock( &rwlock );

  return NULL;

} /* writer */

int main( void ) {

  pthread_t r1, r2, w1, r3, w2, r4, wa, ra, wb, rb, wc, rc, wd, rd;
  unsigned long int i;

#ifdef SOL_SETCONC    /* set concurrency on Solaris machines */
  pthread_setconcurrency( SOL_SETCONC );

  pthread_rwlock_init(&rwlock, NULL);

  pthread_create(&r1, NULL, reader, "reader_1");

  for(i = 0 ; i < 500; ++i);	/* delay */

  pthread_create(&r2, NULL, reader, "reader_2");

  for(i = 0; i < 500; ++i);	/* delay */

  pthread_create(&w1, NULL, writer, "writer_1");

  for(i = 0; i < 500; ++i);	/* delay */

  pthread_create(&r3, NULL, reader, "reader_3");

  for(i = 0; i < 500; ++i);	/* delay */

  pthread_create(&w2, NULL, writer, "writer_2");

  for(i = 0; i < 500; ++i);	/* delay */

  pthread_create(&r4, NULL, reader, "reader_4");

  pthread_create(&ra, NULL, reader, "reader_a");
  pthread_create(&wa, NULL, writer, "writer_a");

  pthread_create(&rb, NULL, reader, "reader_b");
  pthread_create(&wb, NULL, writer, "writer_b");

  pthread_create(&rc, NULL, reader, "reader_c");
  pthread_create(&wc, NULL, writer, "writer_c");

  pthread_create(&rd, NULL, reader, "reader_d");
  pthread_create(&wd, NULL, writer, "writer_d");

  /* join all threads before exiting */
  pthread_join(r1, NULL);
  pthread_join(r2, NULL);
  pthread_join(w1, NULL);
  pthread_join(r3, NULL);
  pthread_join(w2, NULL);
  pthread_join(r4, NULL);
  pthread_join(wa, NULL);
  pthread_join(ra, NULL);
  pthread_join(wb, NULL);
  pthread_join(rb, NULL);
  pthread_join(wc, NULL);
  pthread_join(rc, NULL);
  pthread_join(wd, NULL);
  pthread_join(rd, NULL);

  /* done */
  return 0;


      Gabriel L.  Somlo                 Assistant System Administrator

 Computer Science Department
  Colorado State University             e-mail:
   601 Howes St. 2nd Floor               phone: +1 (970) 491-5305
   Fort Collins,  CO 80523

Your use of Yahoo! Groups is subject to

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]