Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 49 lines (43 sloc) 1.03 KB
#include <stdio.h>
#include <stdbool.h>
#include <pthread.h>
bool receiveDone = false;// change volatile here
#ifdef USE_MUTEX
pthread_mutex_t lock;
#define MUTEX_LOCK pthread_mutex_lock(&lock)
#define MUTEX_UNLOCK pthread_mutex_unlock(&lock)
#define MUTEX_DESTROY pthread_mutex_destroy(&lock)
#else
#define MUTEX_LOCK
#define MUTEX_UNLOCK
#define MUTEX_DESTROY
#endif
void *interrupt_fake(void *vargp)
{
sleep(1);
printf("Interrupt \n");
MUTEX_LOCK;
receiveDone = true;
MUTEX_UNLOCK;
return NULL;
}
int main()
{
pthread_t thread_id;
printf("Thread start\n");
pthread_create(&thread_id, NULL, interrupt_fake, NULL);
while(1)
{
MUTEX_LOCK;
if(receiveDone)
{
MUTEX_UNLOCK;
printf("Running\n");
sleep(1);
} else {
MUTEX_UNLOCK;
}
}
MUTEX_DESTROY;
return 0;
}
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.