Praveen S wrote: > Hi, > > Lets assume the database is nothing but a file where i write if some > application can got access to it or not. Say i write a True value when it > gains access and on exit i make it false. But suppose the application gains > access to the file and writes a true value but it exits abnormally then > other applications which also use the same shared object library will check > the value in that file. They wil find it true. > > And yes the value is changed to false after every reboot because we know no > application will be running on reboot which uses that library. All are > executed only after bootup of device. > > So i want to get a design where > 1) We can handle abnormal termination scenario > 2) We can unlock based on abnormal termination. > > > TIA > Praveen
Get a process ID/thread ID/something that uniquely identifies the process that other processes can also calculate (e.g. have access to the running process list to find the process ID). Write your 'true' to the file and follow that with the unique ID. Or just store the unique ID: If there isn't one, then it is unlocked. If there is one, then it is locked by the process with that unique ID. Then, when you go to run a database query, check to see if it is locked by checking for 'true' AND then see if the process is running (process ID). If it is, wait for 'false' or the process to exit (e.g. abnormal exit). If multiple processes could be waiting for the database, you have to be VERY careful to not enter a deadlock scenario or a scenario where more than one process could have access. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/
