Thread: threaded program doesn't work?

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    13

    threaded program doesn't work?

    I created the following multi-threaded program in linux:
    Code:
    #include <pthread.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    //using namespace std;
    
    void *thread_funk(void *start);
    
    void *thread_funk(void *start)
    {
       int *value1 = (int *)start;
       //while(*value1 < 4)
       while(1) {
          if (*value1 == 3) 
    	{
              printf("Cifra je %d\n", *value1);
    	  pthread_exit(NULL);
    	}
       }
       
    }
    
    int main(int argc, char *argv[])
    {
       pthread_t thread1;
       int *value = (int *)malloc(sizeof(int));
       *value = 0;
       // Create new thread.
       pthread_create(&thread1, NULL, (void *)&thread_funk, (void *)value);
       while(*value < 5)
       {
           //sleep(5);
           *value++;
       }
       free(value);
       exit(0);
    }
    It compiles perfectly bit it would not work! Why?
    Please help.

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    13
    Ok. Found it and fix it and it works now perfectly

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't figure out why this program won't work
    By Northstar in forum C Programming
    Replies: 6
    Last Post: 11-26-2007, 11:31 AM
  2. The Bludstayne Open Works License
    By frenchfry164 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-26-2003, 11:05 AM
  3. Can't get program to work
    By theirishrover12 in forum C Programming
    Replies: 1
    Last Post: 06-08-2002, 11:10 AM
  4. Threaded program
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 03-02-2002, 01:00 PM
  5. how does this program work
    By ssjnamek in forum C++ Programming
    Replies: 2
    Last Post: 01-02-2002, 01:48 PM