[lkml]   [2005]   [Apr]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: Doubt Regarding Multithreading and Device Driver
On Wed, 27 Apr 2005, k8 s wrote:

> hello,
> I have a doubt regarding user space threads and device drivers
> implementation issue.
> I have a device driver for /dev/skn
> It implements basic driver operations skn_open,skn_release, skn_ioctl.
> I am storing something into struct file*filp->private_data.
> As this is not shared across processes I am not doing any locking
> stuff while accessing or putting anything into it.
> Will There be a race condition in a multithreaded program in the ioctl
> call on smp kernel accessing filp->private_data.

Of course. But that's not the only race. You need to make certain that
any shared resource (your driver) only allows a single execution-
thread anywhere there is shared data or the hardware itself. This
is generally accomplished with semaphore(s), a.k.a, down() and up().

Note that each open() call provides its own 'struct file' pointer.
The kernel won't get them mixed up. You can use your private-data
pointer available in this structure in each open() and use that
for private data in each access. You can free such private data
in a close(). But, that's just the obvious stuff. User-mode threads
share open files!

That means that your driver has no way of isolating such access
except by using semaphores.

> S.Kartikeyan

Dick Johnson
Penguin : Linux version 2.6.11 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-04-27 17:43    [W:0.049 / U:1.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site