Skip to content

Commit

Permalink
jekyll build from Action 025c5ff
Browse files Browse the repository at this point in the history
  • Loading branch information
jgoeders committed May 1, 2024
0 parents commit 72d5b8d
Show file tree
Hide file tree
Showing 57 changed files with 7,540 additions and 0 deletions.
Empty file added .nojekyll
Empty file.
Binary file added assets/clang-format.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/format-on-save.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/import-code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions assets/locks.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int glob = 0;
static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;

void *thread_func(void *arg) {
int loops = *((int *)arg);
int loc;

for (int i = 0; i < loops; i++) {
pthread_mutex_lock(&mtx);
loc = glob;
loc++;
glob = loc;
pthread_mutex_unlock(&mtx);
}

return NULL;
}

int main() {
printf("******* Threading Example *******\n");
pthread_t thread1;
pthread_t thread2;
int loops = 10000000;

if (pthread_create(&thread1, NULL, thread_func, &loops)) {
printf("An error occurred while creating thread.\n");
return EXIT_FAILURE;
}

if (pthread_create(&thread2, NULL, thread_func, &loops)) {
printf("An error occurred while creating thread.\n");
return EXIT_FAILURE;
}

pthread_join(thread1, NULL);
pthread_join(thread2, NULL);

printf("glob = %d\n", glob);

return EXIT_SUCCESS;
}
36 changes: 36 additions & 0 deletions assets/threads.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void *do_work(void *arg);

int main() {
printf("******* Threading Example *******\n");
pthread_t thread;
int i = 0;

if (pthread_create(&thread, NULL, do_work, NULL)) {
printf("An error occurred while creating thread.\n");
return EXIT_FAILURE;
}

printf("Parent: Hi!\n");
for (int i = 0; i < 10; i++) {
printf("Parent: Doing work... (%d)\n", i);
sleep(1);
}

pthread_exit(NULL);
return EXIT_SUCCESS;
}

void *do_work(void *arg) {
printf("Child: Hi!\n");

for (int i = 0; i < 10; i++) {
printf("Child: Doing work... (%d)\n", i);
sleep(1);
}
pthread_exit(NULL);
}
Binary file added assets/under-construction.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/vim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 72d5b8d

Please sign in to comment.