[REBOL] Antwort: How does one persist data? Re:(2)

2000-10-12 Thread kracik

Hi,

I forgot to include some description how it should work. The guarded
file is not %lockdir/lock, but any other file - because read-only
accesses to the file don't need to be guarded, and would fail if the
guarded file is currently renamed. You should make a directory
%lockdir/ with an empty file %lock

then you should use:

obtain-semaphore
something: read %my-guarded-file.txt
write %my-guarded-file.txt "something new"
release-semaphore

If you want to only read from your file, you can use just
something: read %my-guarded-file.txt
print something

If I remember correctly, you must only guard one situation,
"read-modify-write", because two simultaneous reads do not interfere,
and two simultaneous writes are a logic error of your program.

obtain-semaphore function uses loop and random wait interval to have a
better chance of succeeding if several processes run it simultaneously.
release-semaphore function should be simpler, loop is not necessary:

release-semaphore: func [] [
if not error? try [ rename %lockdir/lock.locked %lock ] [
return
]
print "Could not release semaphore"
quit
]

-- 
Michal Kracik

[EMAIL PROTECTED] wrote:
> 
> Thank you Mr. Kracik!
> 
> If only I undersatood completely whats going on in the script. Please
> correct me if I´m wrong:
> 1.Files in use are flagged with "semaphore"
> 2. The files in use are renamed as "%lock.locked"
> 
> The script loops, continues to "Try" to rename, if it encounters an error
> then it "waits". Wonßt I get an error anyway if the file is directly
> renamed when I CGI script user requests a file?
> 
> Excuse my newbie question
> 
> Best regards
> 
> Sharriff Aina
> med.iq information & quality in healthcare AG
> Gutenbergstr. 42
> 
> 
> [EMAIL PROTECTED]
> km.czAn: [EMAIL PROTECTED]
>  Kopie:
> 11.10.00 Thema:  [REBOL] How does one persist data? 
>Re:
> 21:56
> Bitte
> antworten an
> list
> 
> 
> 
> Hi Sharriff,
> 
> be careful when saving to a file and reading it later, as many users
> may run your CGI programs simultaneously. You should use some form of
> inter-process synchronization to serialize access to your file. AFAIK
> from REBOL you can reliably synchronize by opening TCP sockets or
> renaming a file. I use these two functions:
> 
> obtain-semaphore: func [] [
> loop 100 [
> if not error? try [ rename %lockdir/lock %lock.locked ] [
> return
> ]
> wait ( random 5 ) / 10
> ]
> print "Could not obtain semaphore"
> quit
> ]
> 
> release-semaphore: func [] [
> loop 100 [
> if not error? try [ rename %lockdir/lock.locked %lock ] [
> return
> ]
> wait ( random 5 ) / 10
> ]
> print "Could not release semaphore"
> quit
> ]
> 
> --
> Michal Kracik
> 
> [EMAIL PROTECTED] wrote:
> >
> > Does anyone have a soultion of persisting data across HTML pages? I want
> > data submitted through a CGI from a HTML form to be usable in other
> pages.
> >
> > Many thanks for the anticipated help guys
> >
> > Sharriff Aina
> > med.iq information & quality in healthcare AG




[REBOL] Antwort: How does one persist data? Re:(2)

2000-10-11 Thread COUSSEMENT . C

Those solution works find but it can become buggy to manage the files
(location, versions, ...)

The solution I used with precisely the same problem you mentionned is to use
the form hidden field element to pass the global vars.

My first HTMLpage calls a REBOL-cgi script, passing some args this script
uses to generate another page which in turn contains a form with some hidden
field containing the global data.

""
""
""
""
""
""
""
""
""

You can so pass your args through your app, and call them when you need
it...

I hope it will work for you ! Do not hesitate to ask I there is any problem.

C. COUSSEMENT 
 e-mail:  [EMAIL PROTECTED] 
 


 


> -Original Message-
> From: [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED]]
> Sent: woensdag 11 oktober 2000 10:52
> To:   [EMAIL PROTECTED]
> Subject:  [REBOL] Antwort:  How does one persist data? Re:
> 
> 
> Thanks Andrew, I´ll try that out.
> 
> Sharriff Aina
> med.iq information & quality in healthcare AG
> 
> 
> 
>  
> 
> [EMAIL PROTECTED]
> 
> o.nz An: [EMAIL PROTECTED]
> 
>  Kopie:
> 
> 11.10.00 Thema:  [REBOL] How does one
> persist data? Re:   
> 10:09
> 
> Bitte
> 
> antworten an
> 
> list
> 
>  
> 
>  
> 
> 
> 
> 
> 
> Sharriff wrote:
> > Does anyone have a solution of persisting data across HTML pages? I want
> data submitted through a CGI from a HTML form to be usable in other pages.
> 
> Why not have a Rebol cgi script that outputs the HTML form, another one
> that
> responds to the form and then writes the information as a file, then
> another
> one that reads the file and writes the information as html again? Or,
> failing that, have the Rebol script on the site FTP the data to the site?
> 
> I hope that helps somewhat.
> 
> Andrew Martin
> ICQ: 26227169
> http://members.nbci.com/AndrewMartin/
> -><-
> 
> 
> 
>