You could take advantage of a shared semaphores and a small shared memory. Let's call the semaphore mutex
and the shared memory bool is_authenticated
. mutex
is initialized with a value of 1 and is_authenticated
with a value of false.
Then your authentication process becomes:
wait(mutex);
if (!is_authenticated)
authenticate();
is_authenticated = true;
signal(mutex);
You would then have to take care of authentication expiration. So when the session is over:
wait(mutex);
assert(is_authenticated == true); /* if not, you have been compromised */
deauthenticate();
is_authenticated = false;
signal(mutex);