Date: Tue, 18 Aug 2015 11:41:34 -0700 From: Leonardo Fogel <leonardofogel@yahoo.com.br> To: freebsd-drivers@freebsd.org Subject: Race conditions Message-ID: <1439923294.98963.YahooMailBasic@web120801.mail.ne1.yahoo.com>
next in thread | raw e-mail | index | archive | help
Hi. The following code is an exerpt from the FreeBSD Architecture Handbook, cha= pter 11.1.1. Sample Driver Source. I've included labels i1, i2, i3. int mypci_open(struct cdev *dev, int oflags, int devtype, struct thread *td) { struct mypci_softc *sc; /* Look up our softc. */ i1: sc =3D dev->si_drv1; device_printf(sc->my_dev, "Opened successfully.\n"); return (0); } static int mypci_attach(device_t dev) { struct mypci_softc *sc; ... i2: sc->my_cdev =3D make_dev(&mypci_cdevsw, device_get_unit(dev), UID_ROOT, GID_WHEEL, 0600, "mypci%u", device_get_unit(dev)); i3: sc->my_cdev->si_drv1 =3D sc; printf("Mypci device loaded.\n"); return (0); } As I understand it, as soon as instruction at label i2 completes, there is = a rare possibility that another thread opens the device file and executes t= he instruction at i1, before the instruction at i3 is executed. Is it corre= ct? How could one fix it? Thank you for your time. Leonardo
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1439923294.98963.YahooMailBasic>