Hi, I am giving here the mechanism I intend to use in my module to avoid race conditions. I use kernel 2.4.20-8, on a uniprocessor system. Please suggest if you find any problems with it. 1. This module would be used by a single user space process, never can it happen that it is being used by more than user space process 2. This module has 8 functions -- two netfilter hook call back functions, pre_routing, local_out hooks 2 timer call back functions a char device drivers, read/write/poll/open functions 3. Here I assume, the timer expiry handlers occur in interrupt contexts (that is they can pre-empt the read/write calls of the char device etc). I am not sure about the netfilter hook functions if they can do the same, any clues ?? Since I am not sure I assume they can per-empt read/write etc too and each other also, though there is no reason to suspect that. 4. The char device has no hardware, it is a dummy device, used as a control interface b/w the user space process and the module(it is the same user process that reads data captured by netfilter hook functions, no other user space process uses this module ) 5. I need this mechanism, since these functions use shared global variables, like write() and timer_expiry1() writes to certain variables that is being used by hook functions /* two global variables */ spinlock_t my_lock=SPIN_LOCK_UNLOCKED; unsigned long my_flags; pre_routing() { spin_lock_irqsave(&my_lock, flags); /****** PROCESS WHATEVER *******/ spin_unlock_irqrestore(&my_lock, flags); } local_out() { /*** I USE THE SAME lock and flags variable in al functions ****/ spin_lock_irqsave(&my_lock, flags); /****** PROCESS WHATEVER ******/ spin_unlock_irqrestore(&my_lock, flags); } Timer1_expiry(){ spin_lock_irqsave(&my_lock, flags); /****** PROCESS WHATEVER ******/ spin_unlock_irqrestore(&my_lock, flags); } timer2_expiry() { spin_lock_irqsave(&my_lock, flags); /****** PROCESS WHATEVER ******/ spin_unlock_irqrestore(&my_lock, flags); } read() { spin_lock_irqsave(&my_lock, flags); /****** PROCESS WHATEVER, uses copy_to_user ******/ /*** the current process might go to sleep here when theres nothing to read, should not matter since I am using irqsave ***/ spin_unlock_irqrestore(&my_lock, flags); } block() { /*... the block call for the char device(called by read), when there is nothing to read */ return wait_event_interruptible(...); } write(){ spin_lock_irqsave(&my_lock, flags); /****** PROCESS WHATEVER, uses copy_from_user .. ******/ /*** process might go to sleep if the user variable from which data is being written is swapped out, shld not matter since I am using irqsave ****/ spin_unlock_irqrestore(&my_lock, flags); } poll() { havent thought about this ; } So How does it look, any obvious flaws ?, something I can do better. Any suggestions are welcome. thanks Amit -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/