HewlettPackard / HewlettPackard/nvthreads

xrun.h stuck waiting for token

Open
#4 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
27
Forks
8
PR merge metrics
No merged PRs in 30d

Description

Executing the code below has significant probability of not completing.
Code gets stuck in `xrun.h`, waiting for the token, with threads burning 100% CPU.

Code TL;DR: Spawn N threads. Each thread will read a counter, print its value, and increment it -- all inside a critical section.

```c
#define NUM_THREADS 3

struct thread_args {
int id;
}

pthread_mutex_t m;
int *counter;

void *thread_start(void *arg) {
struct thread_args *args = (struct thread_args *) arg;
int id = args->id;
sleep(id);
pthread_mutex_lock(&m);
lprintf(">> thread %d read counter: %d\n", id, *counter);
*counter[i]++;
pthread_mutex_unlock(&m);
return 0;
}

int main() {
pthread_t tid[NUM_THREADS];
struct thread_args args[NUM_THREADS];
counter = (int*) nvmalloc(sizeof(int), (char*)"counter");
if(isCrashed()) {
nvrecover(counter, sizeof(int), (char*)"counter");
} else {
*counter = 0;
}
pthread_mutex_init(&m, NULL);
for(int i=0; i

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.