Linux lock problem

Hi Team,

I have a requirement to access a shared resource from the user and interrupt context. What type of locking mechanism I have to use for this. Can any body give advice on this.
Thanks in advance.

-Shiva

By lock do you mean a user mode mutex, some kind of file lock or are you doing something with drivers?

Your description needs a lot more detail if you want a usable answer.

1st of all thanks giving reply. Let me clarify my question properly.
I need to synchronize critical region(one data str.) using semaphore or mutex or spin lock.
My reqt is I need to access a data str. in the driver's code from the process context and interrupt context.
For this what locking mechanism is ideal one.

Since you are in kernel mode context you most likely need a spinlock. What you have is called a critical section.

5.5. Spinlocks discusses spinlocks in general.

Since you asked this question I would recommend lots of reading on your own. FIRST. It is easy to crash or hang the system with slightly less than perfect code. Debugging kernel code can be painful, some debugging tools may still require using two physically separate computers.

It is easier to do your homework first. Write dirt simple code for practice, first.

1 Like

Thanks Jim for your reply and relevant links.