You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In chardev2.c, Compare-And-Swap operation is used in device_open() to avoid concurrent access to the shared resources:
/* This is called whenever a process attempts to open the device file */staticintdevice_open(structinode*inode, structfile*file)
{
pr_info("device_open(%p)\n", file);
/* We don't want to talk to two processes at the same time. */if (atomic_cmpxchg(&already_open, CDEV_NOT_USED, CDEV_EXCLUSIVE_OPEN))
return-EBUSY;
try_module_get(THIS_MODULE);
returnSUCCESS;
}
But what if a process opens the device, then triggers a fork(2). Can these two processes have concurrent access to the device? (we called open(2) only once)