Skip to content

Commit

Permalink
Add multithreaded example
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-schwarz committed Jan 27, 2024
1 parent 036bbc6 commit 55dacde
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/regression/79-mutex2/02-split-mt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include<pthread.h>

pthread_mutex_t m1;
pthread_mutex_t m2;
pthread_mutex_t* ptr;

void other() {
int top;
ptr = &m2;

if(top) {
ptr = &m1;
}
}

int main(int argc, char const *argv[])
{
int top;

ptr = &m1;

if(top) {
ptr = &m2;
}

pthread_t mischievous;
pthread_create(&mischievous, NULL, other, NULL);


pthread_mutex_lock(ptr);

// This has to produce a warning, as the other thread may have changed what
// ptr points to such that it's not the same mutex being unlocked here.
pthread_mutex_unlock(ptr); //WARN

return 0;
}

0 comments on commit 55dacde

Please sign in to comment.