Re: [sqlite] lockfile but using db table row instead of file
On 9/4/19, Keith Medcalf wrote: > > On Wednesday, 4 September, 2019 04:40, Peng Yu wrote: > >>The command line program `lockfile` locks based on files. I wants to do the >>same thing but based on a row in a table. For example (this is just one >>example feature, but all other features should also be preserved), if a >>given row is there, the process will hang unless some other process delete >>the given row. Multiple processes can compete for the same row. Because >>program like this should deal with concurrency, I am not clear how to make >>it bug free. Does anybody has a ready-to-use solution? Thanks. > > Lockfile is a program that implements lockfiles for *nix shell scripts. Why > would you want to re-create that? If you want to co-ordinate access to > something between processes and/or threads in programs written in C then why > not just use the OS provided named semaphore interface and skip all the > extra complication (and let the OS do all the work, that’s why it was > written)? I use lockfile to ensuring one process runs when dealing with file dependencies (as in build systems such as make which takes care of file dependencies). Now I put some files in sqlar. Therefore, I'd like to have something as a natural extension of lockfile's feature to deal with files in sqlar. However, since sqlite db is locked per file, there is no way to concurrently change two files in sqlar anyway. In this sense, my question seems not to matter anymore. -- Regards, Peng ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] lockfile but using db table row instead of file
What Keith said, plus, SQLite does not do row locking, period. It's a full file lock when required. SQLite has some embedded functionality to deal with locking things like this, and your program will need to be written to be aware of how to deal with locking. If you're attempting to fix race conditions, then you need to look at how your programs are working with each other, either by communicating with each other through FIFO files (If linux) or through DDE (Dynamic Data Exchange) if Windows, or rely on the OS and SQLite provisions already out there. I've done some LIGHT work with DDE back in the Delphi 5 days, and from what I remember, it was pretty interesting. Work with the tools you have, and don't go reinvent the wheel. (Unless the purpose is to reinvent the wheel just for fun.) On Wed, Sep 4, 2019 at 6:40 AM Peng Yu wrote: > The command line program `lockfile` locks based on files. I wants to do the > same thing but based on a row in a table. For example (this is just one > example feature, but all other features should also be preserved), if a > given row is there, the process will hang unless some other process delete > the given row. Multiple processes can compete for the same row. Because > program like this should deal with concurrency, I am not clear how to make > it bug free. Does anybody has a ready-to-use solution? Thanks. > -- > Regards, > Peng > ___ > sqlite-users mailing list > sqlite-users@mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users > ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] lockfile but using db table row instead of file
On Wednesday, 4 September, 2019 04:40, Peng Yu wrote: >The command line program `lockfile` locks based on files. I wants to do the >same thing but based on a row in a table. For example (this is just one >example feature, but all other features should also be preserved), if a >given row is there, the process will hang unless some other process delete >the given row. Multiple processes can compete for the same row. Because >program like this should deal with concurrency, I am not clear how to make >it bug free. Does anybody has a ready-to-use solution? Thanks. Lockfile is a program that implements lockfiles for *nix shell scripts. Why would you want to re-create that? If you want to co-ordinate access to something between processes and/or threads in programs written in C then why not just use the OS provided named semaphore interface and skip all the extra complication (and let the OS do all the work, that’s why it was written)? -- The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume. ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users