diff --git a/Further pthread practice Qs/1.c b/Further pthread practice Qs/1.c deleted file mode 100644 index 2abb934..0000000 --- a/Further pthread practice Qs/1.c +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -#include - -#define NUM_THREADS 20 - -void *fizzbuzz(void *arg) { - int *number = (int *) arg; - if (*number % 3 == 0) { - printf("%d -> %s\n", *number, "fizz"); - } else if (*number % 5 == 0) { - printf("%d -> %s\n", *number, "buzz"); - } else { - printf("%d -> %s\n", *number, "no div"); - } - - pthread_exit(NULL); -} - -int main() { - - pthread_t threads[20]; - int nums[20]; - - int i; - for (i = 0; i < NUM_THREADS; i++) { - nums[i] = i + 1; - pthread_create(&threads[i], NULL, fizzbuzz, &nums[i]); - } - - for (i = 0; i < NUM_THREADS; i++) { - char *returnedStr; - pthread_join(threads[i], (void **) &returnedStr); - } - - pthread_exit(NULL); - -} diff --git a/Further pthread practice Qs/3.c b/Further pthread practice Qs/3.c deleted file mode 100644 index 527a922..0000000 --- a/Further pthread practice Qs/3.c +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include -#include -#include // gives us sleep(). Replace with windows.h for compiling on windows! - -#define NUM_THREADS 20 - -typedef struct _threadinfo { - bool * keepRunning; - int * total; -} threadinfo_t; - -void * getInput(void * arg) { - threadinfo_t * args = (threadinfo_t *) arg; - - int currInput; - printf("Input as much as you can --- you have 10 seconds!\n"); - while (*args->keepRunning) { - printf("Add another number! : "); - scanf("%d", &currInput); - *args->total += currInput; - } - pthread_exit(NULL); -} - -int main() { - - pthread_t thread; - bool keepRunning = true; - int total = 0; - threadinfo_t args = {&keepRunning, &total}; - - pthread_create(&thread, NULL, getInput, &args); - - sleep(10); // sleep for 10 secs - keepRunning = false; - pthread_join(thread, NULL); - printf("\n\nYou managed to enter a total of: %d!\n", total); - - pthread_exit(NULL); - -} - diff --git a/Further pthread practice Qs/5.c b/Further pthread practice Qs/5.c deleted file mode 100644 index f7cdef3..0000000 --- a/Further pthread practice Qs/5.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -// the rest is up to you! Implement a program which starts _two_ pthreads. -// One reads input from the user, and adds numbers to a total. -// the other prints the current total value every 3 seconds. -// After 30 seconds, the main thread sets a bool to false that signals -// to both threads that they should join, just like in 3.c. -// You can use sleep(int seconds) from unistd.h to make your threads sleep. \ No newline at end of file diff --git a/Further pthread practice Qs/further_pthread_practice.pdf b/Further pthread practice Qs/further_pthread_practice.pdf deleted file mode 100644 index 2962c7c..0000000 Binary files a/Further pthread practice Qs/further_pthread_practice.pdf and /dev/null differ