Re: Locking in ISAM files
Posted in 2007
amit.atray@gmail.com wrote: > On Jul 27, 9:07 am, Jonathan Leffler <jleff...@earthlink.net> wrote: >> amit.at...@gmail.com wrote: >>> I intend to use, record level manual locking on ISAM files. >>> my code will be somewhat like below >>> ====================================================== >>> fd_emp = isopen ("employee",ISINOUT+ISMANULOCK); >>> isread (fd_emp,emprec,ISEQUAL+ISLOCK); >>> /* records are still locked */ >>> isrelease (fd_emp); >>> /* employee record are unlocked */ >>> ===================================================== >>> I have slight confusion about same, Is it mandatory to use isrelease >>> call to release lock? If I just close file description with >>> isclose(fd_emp), then still I have to use isrelease. >> If you close the file instead, the locks will be released. >> >>> Will this piece of code will work fine in mutlithreaded server. >> Not exactly as written, because you'll have to control access to C-ISAM >> calls. C-ISAM uses a number of global variables and is not itself a >> thread-safe library, so your multi-threaded application will have to >> ensure that two threads are not concurrently using C-ISAM. >> >>> I don't know much about internal implementation of lock, but here I am >>> using file descriptor to remove lock (isrelease(fd_em) ) So how will >>> this be handled in case of threads???? How will ISAM know, which >>> thread has locked, and which hasn't?? >> C-ISAM, being thread-unaware, won't handle locking between threads. >> AFAIK, the fcntl() system call, used to implement the locking, is not >> able to lock between threads either. >> >> If you did have something that locked between threads, you'd have to >> worry about deadlock within the application. > > If My Program is read/writing 15 different file in Multithreaded > Environment, if Thread1 is writing to file1, will it be cause > Blocking of Thread2 to write on File2, ? because of global variable > you mentioned ? > > I want to have Record level read/write done by Multithreaded program > in Fastest possible way Global variables are global - equally accessible to every thread in the program. Consequently, to get any sort of sane behaviour in a single process, you will have to prevent concurrent access to the global variables, which also means ensuring that each C-ISAM call will be protected (and a little extra scope too - the extra being necessary to garner the relevant information from the global variables, or set the relevant information into them for C-ISAM to use). If you need separate activity going on concurrently and want to use C-ISAM, use separate processes (as with Informix SE, Standard Engine). -- Jonathan Leffler #include <disclaimer.h> Email: jleffler@earthlink.net, jleffler@us.ibm.com Guardian of DBD::Informix v2007.0226 -- http://dbi.perl.org/