On Apr 12, 3:31 am, peter koch
> On 11 Apr., 17:42, Alexander Dong Back Kim
> wrote:
>
>
>
> > Hi all,
>
> > I'm working on a Linux machine and using g++. I'm developing an
> > semaphore module for a number of applications in the system.
>
> > My question scenario is, an application can lock a resource which is
> > shared memory segment in this case, after they locked a segment and if
> > they somehow crash then the lock won't be released because the
> > application locked the resource is dead.
>
> > I hope there must be a way to release the lock so solve this problem
> > even the application is crashed unexpectedly.
>
> > Any idea?
>
> > best regards,
>
> > Alex D. B. Kim
>
> This should be possible with some kind of heavyweight structure, but
> the interesting question is why you would ever want to do that! If the
> application crashes while it holds the semaphore, this datastructure
> should by definition be defined as corrupted.
> As to how to do it, I suggest a Linux group.
>
> /Peter
Hi Peter,
The reason why I'm looking for this solution is, currently, I'm
developing an real time system using IPC. In the system, many
processes will run at the same time and they are independent from each
other. They also need to share their data so they are using shared
memory as a medium. However, since they can access and update the
shared memory simultaneously, I have been asked to implement a
implementation of a read/write lock for the multiple applications.
Therefore, I chose semaphore for this.
The problem of semaphore is, although they works beautifully, if a
process lock the semaphore and crashes immediately after the lock,
then the lock won't be unlocked. Therefore, there is no way other
applications can access the locked resource. Because of this reason, I
think I have to somehow protect unexpected terminations. In other
words, in order to unlock the resource before the process dies, I
think I have to catch some system message or destructor of the class.
I tried destructor way but it didn't call the destructor when the
application is unexpectedly killed.
Any suggestion for solving this problem?
Cheers,