UNIX threads:

1. Introduction to threads (pthreads)

#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void* routine() {
    printf("Hello from threads\n");
    sleep(3);
    printf("Ending thread\n");
}

int main(int argc, char* argv[]) {
    pthread_t p1, p2;
    if (pthread_create(&p1, NULL, &routine, NULL) != 0) {
        return 1;
    }
    if (pthread_create(&p2, NULL, &routine, NULL) != 0) {
        return 2;
    }
    if (pthread_join(p1, NULL) != 0) {
        return 3;
    }
    if (pthread_join(p2, NULL) != 0) {
        return 4;
    }
    return 0;
}

2. Difference between processes and threads

main-processes.c

main-threads.c

3. What are Race Conditions?

4. What is a mutex in C? (pthread_mutex)

5. How to create threads in a loop (pthread_create)

6. Get return value from a thread (pthread_join)

7. How to pass arguments to threads in C

8. Example: Summing numbers from an array

9. Difference between trylock and lock in C

10. Condition variables in C

11. Signaling for condition variables (pthread_cond_signal vs pthread_cond_broadcast)

12. Example: pthread_mutex_trylock

13. What is pthread_exit?

14. Introduction to barriers (pthread_barrier)

15. Example: barriers (pthread_barrier)

16. What is pthread_t?

17. What are detached threads?

18. Static initializers in the PTHREAD API

19. Deadlocks in C

20. Recursive mutexes

21. Introduction to semaphores in C

22. Example: semaphores (Login Queue)

23. Producer - Consumer Problem in Multi-Threading

24. What are binary semaphores?

25. Difference between Binary Semaphores and Mutexes

26. Getting the value of a semaphore

27. Parallelism vs Concurrency

main-parallelism.c

main-concurrency.c

28. Thread Pools in C (using the PTHREAD API)

29. Thread Pools with function pointers in C

Source:

https://code-vault.net/course/6q6s9eerd0:1609007479575arrow-up-right

Last updated