Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <pthread.h>
- #include <stdlib.h>
- #include <time.h>
- #include <unistd.h>
- #define NUM_THREADS 500
- pthread_t pts[NUM_THREADS+1];
- int freiePlaetze = 100;
- void * status(){
- int z = 0;
- while (z == 0){
- sleep(1);
- printf("Freie Plaetze: %d", freiePlaetze);
- }
- }
- void * parke(){
- freiePlaetze--;
- srand(time(NULL));
- int parkdauer = rand() % 4 + 1;
- sleep(parkdauer);
- freiePlaetze++;
- pthread_exit(NULL);
- }
- int main() {
- // Statusthread erzeugen
- pthread_create(&pts[500], NULL, status, NULL);
- // Autos erzeugen
- int i;
- for (i=0; i < NUM_THREADS; i++) {
- if (freiePlaetze > 0){
- pthread_create(&pts[i], NULL, parke, NULL);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement