Hi,
Let me know if this is the wrong forum but i couldn't find any forum here for threads so i give it a go.
I am using pthreads and c with VS6 to make a threaded program on my p4 with MS Windows XP Pro. I started out with a basic program that is supposed to start one "car" thread and five "passanger" threads. Each of the threads print a fiew words to show that they are running. The weird thing is that sometimes more prints are being made than there are threads, some threads seem to print twice. There is no loop in the function bodies. Also sometimes some letters are missing in the words or some letter is written more than once and sometimes the program hangs. This does not happen very often. Anybody know why?
Here is the code:
#ifndef _REENTRANT
#define _REENTRANT
#endif
#define N 5
#define C 3
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
void *carFunc(void *inCol);
void *pasFunc(void *inCol);
int main(int argc, char* argv[])
{
pthread_t car;
pthread_t passenger[N];
pthread_create(&car, NULL, carFunc, NULL);
for(int i = 0; i < N; i++)
pthread_create(&passenger, NULL, pasFunc, NULL);
pthread_join(car, NULL);
for(i = 0; i < N; i++)
pthread_join(passenger, NULL);
return(0);
}
void *carFunc(void *inCol){
printf("In carFunc\n");
return (NULL);
}
void *pasFunc(void *inCol){
printf("In pasFunc\n");
return (NULL);
}
Thanks for any help!
/Henrik
Let me know if this is the wrong forum but i couldn't find any forum here for threads so i give it a go.
I am using pthreads and c with VS6 to make a threaded program on my p4 with MS Windows XP Pro. I started out with a basic program that is supposed to start one "car" thread and five "passanger" threads. Each of the threads print a fiew words to show that they are running. The weird thing is that sometimes more prints are being made than there are threads, some threads seem to print twice. There is no loop in the function bodies. Also sometimes some letters are missing in the words or some letter is written more than once and sometimes the program hangs. This does not happen very often. Anybody know why?
Here is the code:
#ifndef _REENTRANT
#define _REENTRANT
#endif
#define N 5
#define C 3
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
void *carFunc(void *inCol);
void *pasFunc(void *inCol);
int main(int argc, char* argv[])
{
pthread_t car;
pthread_t passenger[N];
pthread_create(&car, NULL, carFunc, NULL);
for(int i = 0; i < N; i++)
pthread_create(&passenger, NULL, pasFunc, NULL);
pthread_join(car, NULL);
for(i = 0; i < N; i++)
pthread_join(passenger, NULL);
return(0);
}
void *carFunc(void *inCol){
printf("In carFunc\n");
return (NULL);
}
void *pasFunc(void *inCol){
printf("In pasFunc\n");
return (NULL);
}
Thanks for any help!
/Henrik