aboutsummaryrefslogtreecommitdiff
path: root/aufgabe4/conv.c
diff options
context:
space:
mode:
Diffstat (limited to 'aufgabe4/conv.c')
-rw-r--r--aufgabe4/conv.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/aufgabe4/conv.c b/aufgabe4/conv.c
index efa8200..919965c 100644
--- a/aufgabe4/conv.c
+++ b/aufgabe4/conv.c
@@ -1,18 +1,44 @@
/*
* vim:ts=4:sw=4:expandtab
+ *
+ * © 2010 Michael Stapelberg
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
+#include "queue.h"
+
+/*
+ * Conv-Prozess. Generiert Zufallszahlen und schickt sie an den Log-Prozess
+ * sowie an den Statistik-Prozess.
+ *
+ */
void conv() {
- printf("conv started\n");
+ int number;
+ struct msg *first;
+ struct msg *second;
for (;;) {
+ /* Zufallszahl generieren */
+ number = rand();
+
+ /* Zahl zweimal in die Queue schreiben: Einmal zum loggen, einmal für
+ * den Statistik-Prozess */
+ first = queue_write(D_CONV_TO_LOG, number);
+ second = queue_write(D_CONV_TO_STAT, number);
+
+ /* Warten, bis die Zufallszahl aus der Queue geholt wurde */
+ while (first->dir == D_CONV_TO_LOG ||
+ second->dir == D_CONV_TO_STAT)
+ usleep(1);
}
}
+/*
+ * Cleanup-Funktion. Beendet den Prozess.
+ *
+ */
void conv_cleanup() {
- printf("conv cleanup\n");
_exit(EXIT_SUCCESS);
}