mutex: a mistake I made

I defined a shared mutex for processes, in /dev/shmem

The mutex is for protecting the access to a hardware block. Each operation might last for 2 ms.



Wait for “operation completion” interrupt.

When interrupt comes, unlock the mutex;

(if the user wants to stop, unlock the mutex).

If required,

Lock the mutex,

Set up the next operation.


I wanted to only unlock the mutex if it was being locked, therefore, I add some check, an global_variable is_mutex_locked.

Don’t use global variable to indicate if the mutex is locked, or unlock it.



Wait for the operation complete (by reading a DMA status register);

Tell the dedicated thread to exit (by setting a global variable g_dead).

Wait for the dedicated thread exit;



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s