G
Giambattista Bloisi
Hi,
In your opinion there is a faster way to implement a non-blocking
multual exclusion than:
Object sem = new Object();
int count = 0;
void mutex_activity() {
synchronized(sem) {
if(count > 0)
return;
count++;
}
//... activity
synchronized(sem) {
count--;
}
}
I tryed with the following, but it seems to not work properly.
volatile int count = 0;
void mutex_activity() {
if(++count > 1) {
--count;
return;
}
//activity...
--count;
}
Regards,
Giambattista
In your opinion there is a faster way to implement a non-blocking
multual exclusion than:
Object sem = new Object();
int count = 0;
void mutex_activity() {
synchronized(sem) {
if(count > 0)
return;
count++;
}
//... activity
synchronized(sem) {
count--;
}
}
I tryed with the following, but it seems to not work properly.
volatile int count = 0;
void mutex_activity() {
if(++count > 1) {
--count;
return;
}
//activity...
--count;
}
Regards,
Giambattista