Altera_Forum
Honored Contributor
20 years agolocking the mutex
Hi,
Whats wrong with my code?? My system is running with two cpu's. To get started with the different commands I'm just testing with a Hello World app:int main()
{
char *test;
test = mutex_uart1_name;
int i = 0;
while(1)
{
if (altera_avalon_mutex_trylock(&test, 16) == 0)
{
printf("cpu 1: int = %i. hello from nios ii!\n", i);
altera_avalon_mutex_unlock(&test);
i++;
}
usleep(2000000);
}
return 0;
}
The application is running on both cpu's, but even though the trylock returns 0 (=mutex lock ok), the other cpu's also get to lock the mutex, or, i guess, none of them do..... I also wonder why this code is not working (skipping the test-pointer):
int main()
{
int i = 0;
while(1)
{
if (altera_avalon_mutex_trylock(mutex_uart1_name, 0) == 0)
{
printf("cpu 2: int = %i. hello from nios ii!\n", i);
altera_avalon_mutex_unlock(mutex_uart1_name);
i++;
}
usleep(2000000);
}
return 0;
} Stian