Skip to content
Snippets Groups Projects
Unverified Commit 81f85228 authored by abrahas55's avatar abrahas55
Browse files

finished c example code

parent 173f3a4f
Branches
No related tags found
2 merge requests!4Übung2,!3Übung1
...@@ -13,19 +13,40 @@ ...@@ -13,19 +13,40 @@
#include <inttypes.h> #include <inttypes.h>
#include <pthread.h> #include <pthread.h>
void *start_routine(void) { void *start_routine(void *arg) {
(void) arg;
pthread_t pid = pthread_self(); pthread_t pid = pthread_self();
for(size_t i = 0; i < 50; i++) { for(size_t i = 0; i < 50; i++) {
printf("i am thread %llu\n", pid); printf("i am thread %lu\n", pid);
sleep(1); sleep(1);
} }
pthread_exit(); pthread_exit(EXIT_SUCCESS);
} }
int main(int argc, char const *argv[]) { int main(int argc, char const *argv[]) {
(void) argc, argv; (void) argc;
(void) argv;
// ignore this, just to suppress warnings
long unsigned int thread_ids[6];
size_t amount_threads = 5; size_t amount_threads = 5;
for(size_t i = 0; i < amount_threads; i++) {
// we do no error checking!
pthread_create(
&thread_ids[i],
NULL, // default attributes
&start_routine, // what should the thread do
NULL // no arguments for the thread
);
}
// either do this for lazy or join the threads together
while(1) {
puts("main!");
sleep(1);
}
return EXIT_SUCCESS;; return EXIT_SUCCESS;;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment