Locking in IASM files
Posted in 2007
Topics: General Discussion
Hi All, 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. Will this piece of code will work fine in mutlithreaded server. 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??
amit.atray@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. -- Jonathan Leffler #include <disclaimer.h> Email: jleffler@earthlink.net, jleffler@us.ibm.com Guardian of DBD::Informix v2007.0226 -- http://dbi.perl.org/
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. > > -- > Jonathan Leffler #include <disclaimer.h> > Email: jleff...@earthlink.net, jleff...@us.ibm.com > Guardian of DBD::Informix v2007.0226 --http://dbi.perl.org/- Hide quoted text - > > - Show quoted text - 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 Amit