Thread: Pthreads Error "_imp_pthread_create"

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    2

    Pthreads Error "_imp_pthread_create"

    Hey Guys,
    I've learned programming in C in school for about one yearand a half and now I wanted to try myself in parallel programming. I downloaded the Pthread-files and tried to write a sorting program with and without pthreads to compare how fast they are. But when I try to compile my parallel program I get two errors I don't understand:
    "undefined reference to _imp_pthread_create"
    "undefined reference to _imp_pthread_join"
    I can't find any mistakes in my program, maybe anyone of you can help me. This is my Program:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <pthread.h>
    
    void *DieOberen50000 (int a[100000])
    {
    	int i,j,h,m;
    	for (i=100000;i>=50000;i--)
    	{
    		m=i;
    		for (j=0;j<=i;j++)
    		{
    			if (a[j]>a[m])
    			{
    				m=j;
    			}
    		}
    		h=a[m];
    		a[m]=a[i];
    		a[i]=h;
    	}
    }
    
    void *DieUnteren50000(int a[100000])
    {
    	int i,j,h,m;
    	for (i=0;i<=50000;i++)
    	{
    		m=i;
    		for (j=i;j<=100000;j++)
    		{
    			if (a[j]<a[m])
    			{
    				m=j;
    			}
    		}
    		h=a[m];
    		a[m]=a[i];
    		a[i]=h;
    
    	}
    }
    
    void main()
    {
    	int rc,i,a[100000];
    	void *valuep;
    	time_t seconds;
    	pthread_t *Schleife1,*Schleife2;
    
    	srand(time(NULL));
    
    	for (i=0;i<100000;i++)
    	{
    		a[i]=rand() % 10000;
    		printf("%d ",a[i]);
    	}
    
    	printf("\n\n");
    
    	seconds = time (NULL);
    
    	rc = pthread_create(Schleife1,NULL,DieOberen50000, a);
    	rc = pthread_create(Schleife2,NULL,DieUnteren50000,a);
    	rc = pthread_join (*Schleife1,&valuep);
    	rc = pthread_join (*Schleife2,&valuep);
    
    	for (i=0;i<100000;i++)
    	{
    		printf("%d ",a[i]);
    	}
    
    
    	seconds = time(NULL) - seconds;
    
    	printf("\n\n %ld", seconds);
    
    
    	scanf("%d",i);
    }
    PS: I'm using lcc-win32 on Windows Vista.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well you need to add the pthread library (for how, read your compiler manual).

    Something like
    cc prog.c -lpthread

    Problems with your code
    1. main returns int, not void.
    2. scanf("%d",i); needs to be scanf("%d",&i);
    3. DieOberen50000 starts off 1 element past the end of the array
    4. Both functions modify the same middle element.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    2
    Sorry I cant find it in the manual. Please explain to me how to add the library. Furthermore I dont have the prog.cc file, it wasn't in the Pthreads directory I downloaded:
    ftp://sourceware.org/pub/pthreads-win32/

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    1. prog.c is whatever YOU called your source file.

    2. Adding the library should be described in the manual for your lcc-win32 compiler.
    I don't have that compiler installed, so I can't help you with that.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using pthreads with an API that uses pthreads
    By MK27 in forum C Programming
    Replies: 3
    Last Post: 03-06-2009, 02:47 PM
  2. Pthreads performance
    By C_ntua in forum C Programming
    Replies: 42
    Last Post: 06-17-2008, 11:29 AM
  3. Replies: 3
    Last Post: 04-16-2007, 12:02 PM
  4. Difference between win32 and linux pthreads
    By philipsan in forum C Programming
    Replies: 1
    Last Post: 02-07-2006, 04:57 PM
  5. pthreads and resources
    By ubermensch in forum C Programming
    Replies: 2
    Last Post: 02-07-2006, 02:27 AM