Re: Appending a unique line to a file
- From: Brandon Cherry <brandon@xxxxxxxxxxxxxxx>
- Date: Thu, 28 Jun 2007 13:31:09 -0400
Steve Swift wrote:
[snip]
There's obviously more to the code above that I can understand. I'm relatively new to anything with a "~" in it.So this is running on the same machine? Apache generating threads for multiple clients or some similar server?
What's the mechanism that stops two concurrent threads (our server has four processors) getting to the "append" bit and both appending?.
On OS/2 (our previous server) this was simple, as you couldn't open a file for output on more than one thread; OS/2 caused the second to fail.
Use queue to pass from multiple clients to another rexx thread running on the same machine that keeps the writing in one thread.
(Example attached)
--
Brandon Cherry
::routine loadIndexes public
use arg fn
dates = .set~new()
fs = .stream~new(fn)~~open('shareread')
do until fs~lines() == 0
parse value fs~linein with yyyymm .
dates~put(yyyymm)
end
fs~~close()
return datesfn = 'example.txt'
dates = loadIndexes(fn)
call rxqueue 'create', 'myQ'
call rxqueue 'set', 'myQ'
fs = .stream~new(fn)
say 'Press Q to end.'
do forever
if chars() \== 0 then do
parse upper value sysGetKey('noecho') with key
if key == 'Q' then exit
end
do while queued() \== 0
pull userid
say 'Received:' userid
currentDate = substr(date('s'), 1, 6)
if \dates~hasIndex(currentDate) then do
say currentDate userid
dates~put(currentDate)
fs~~open('shareread write append')~~lineout(currentDate userid)~~close()
end
end
call syssleep 0.01
end
::requires 'include.rex'dates = loadIndexes('example.txt')
call rxqueue 'set', 'myQ'
say 'Type Q to end.'
do forever
call charout , 'Enter userid: '
parse upper linein userid
push userid
if userid~left(1, 1) = 'Q' then exit
end
::requires 'include.rex'
- Follow-Ups:
- Re: Appending a unique line to a file
- From: Steve Swift
- Re: Appending a unique line to a file
- References:
- Appending a unique line to a file
- From: Steve Swift
- Re: Appending a unique line to a file
- From: Jeremy C B Nicoll
- Re: Appending a unique line to a file
- From: Steve Swift
- Re: Appending a unique line to a file
- From: Brandon Cherry
- Re: Appending a unique line to a file
- From: Steve Swift
- Appending a unique line to a file
- Prev by Date: Re: Appending a unique line to a file
- Next by Date: Re: Appending a unique line to a file
- Previous by thread: Re: Appending a unique line to a file
- Next by thread: Re: Appending a unique line to a file
- Index(es):
Relevant Pages
|