Hi Stephen!

Yes I consider using the mutex methods of Semaphore but it can not be used in this case:

file: refs/address/save.page

page
    forbidWriting;
    beingWritten: true;
    time: (Time now);
    date: (Date today);                               "modification of page>>date"
    passwordFrom: request book: book;
    alertsFrom: request.
[page
    getIpUser;                                            "modification of page>>user"
    backup;
    write;
    beingWritten: false;
    permitWritting ] fork.

It must be sure that modification of page can not be interrupted until forked process be over.

                                                                                                                    Martin

Stephen Pair wrote:

Martin,

Did you consider using the mutex methods of Semaphore?  It looks like you've
duplicated the mutex functionality with the forbidWriting and permitWriting
scheme.

You could add a "writeMutex" inst var to NuSwikiPage and initialize it with
"Semaphore forMutualExclusion".

Then NuSwikiPage>>forkWrite might look something like:

forkWrite
        [
                self writeMutex critical: [
                        self getIpUser;
                        write
                ]
        ] fork

Or, possibly, the #write method could contain the critical section.

Side note:  We've modified the Semaphore>>critical: as follows:

critical: mutuallyExcludedBlock
        "Evaluate mutuallyExcludedBlock only if the receiver is not currently in
        the process of running the critical: message. If the receiver is, evaluate
        mutuallyExcludedBlock after the other critical: message is finished."

        | blockValue |
        self wait.
        [
                blockValue _ mutuallyExcludedBlock value.
        ] ensure: [
                self signal.
        ].
        ^blockValue

...this is to ensure that in the event of an exception that the semaphore
will get signaled.  But, you need to be careful not to have any
mutuallyExcludedBlocks that potentially have non-local returns (as #ensure:
is not really safe when dealing with NLRs right now...you can in some cases
crash Squeak).

- Stephen

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of
Martin Baco
Sent: Tuesday, May 16, 2000 5:15 AM
To: PWS conference
Subject: [pws] page writing

Hi!
There is a runnig Comanche/Swiki server in our company but it become freeze
for time to time. Once when swiki crashed I found a page no completely saved
in a file. I looked over the swiki source and I found that every page is
guarded by instance variable beingWritten. This variable is true if there is
a forked process which saves page on disk But I think that two such
processes (which want to save same page) can foul. I think that better way
is control an access to every  page by semaphore. Attached file contains
change set which provides you this solution.

Martin Baco

Reply via email to