From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Sun, 8 Feb 1998 10:52:58 -0600 From: G. David Butler gdb@dbSystems.com Subject: [9fans] create(2)/open(2) race for file creation Topicbox-Message-UUID: 720625d2-eac8-11e9-9e20-41e7f4b1d025 Message-ID: <19980208165258.KnUBX7arnUXb9Z4f-JytkmmILRpr7TeQpzU4Iurys8M@z> I hate when I'm in too much of a hurry. I need to be more complete here. Also, this happens 30 times a *second* in my application. >From: "G. David Butler" >>From: "Dave Presotto" >>This is why I got ken to introduce exclusive access files. I >>use one as a lock for a directory/file/whatever. > >I tried that with: > >open(lock file in directory) >if open fail { > create > write > close >} >close(lock file) The real code is more like: while(open(lock file) fails) /*sleep(some amount if you want)*/; because the open to an exclusive file does not block. Also I forgot to add the many clone(5)s. >if open fail { > create > write > close >} >close(lock file) > >But the 9p overhead and the bottleneck created convinced me that >it was not a good idea. The above becomes: > >open(2) clone(5) > walk(5) > open(5) >open(2) clone(5) > walk(5) [fails] clunk(5) >create(2) clone(5) > walk(5) [create(2) trying to determine to send the create(5)] clunk(5) > create(5) >write(2)... >close(2) > clunk(5) >close(2) > clunk(5) > >If we change create(2) to do create(5) then: > >if create() success { > write > close >} > >becomes: > >create(2) > create(5) >write(2)... >close(2) > clunk(5) > >Much better. David Butler gdb@dbSystems.com