Edited slides again (lol slices)

This commit is contained in:
Zhengyi Chen 2023-12-06 21:09:25 +00:00
parent 1fbefd49f0
commit 551cedb8cd
4 changed files with 71 additions and 11 deletions

View file

@ -7,14 +7,14 @@
// Shared variable
int a = 1;
void *foo(void *_noarg) {
void foo(void) {
while (a)
asm volatile ("":::"memory");
printf("Exiting from foo...\n");
exit(EXIT_SUCCESS);
}
void *bar(void *_noarg) {
void bar(void) {
a = 0;
printf("Exiting from bar...\n");
exit(EXIT_SUCCESS);
@ -24,13 +24,15 @@ int main(int argc, char** argv) {
const size_t NR_THREADS = 2;
pthread_t *threads = calloc(NR_THREADS, sizeof(pthread_t));
int ret_create_thread_1 = pthread_create(&threads[0], NULL, foo, NULL);
int ret_create_thread_1 = pthread_create(
&threads[0], NULL, (void *(*)(void *))foo, NULL);
if (ret_create_thread_1) {
perror("Failed to create pthread for `foo`.");
exit(EXIT_FAILURE);
}
int ret_create_thread_2 = pthread_create(&threads[1], NULL, bar, NULL);
int ret_create_thread_2 = pthread_create(
&threads[1], NULL, (void *(*)(void *))bar, NULL);
if (ret_create_thread_2) {
perror("Failed to create pthread for `bar`.");
pthread_cancel(threads[0]);