Go Back   FlashFXP Forums > >

Programming Need help with C/C++/Delphi? Ask here and make us all laugh.

Closed Thread
 
Thread Tools Rate Thread Display Modes
Old 11-16-2003, 05:51 PM   #1
darkone
Disabled
FlashFXP Registered User
ioFTPD Administrator
 
darkone's Avatar
 
Join Date: Dec 2001
Posts: 2,230
Default iTCL

lockobject
open <lockname> <event/semaphore/spinlock> [autoreset value/semaphore count]
- returns lockId on success, 0 on error. If lock does exist, new lock is created
wait <lockId> <timeout/spincount> [wait count]
- returns 0 on success, 1 on timeout, -1 on error. Optional argument wait count is used by semaphores.
set <lockId> [set count]
- returns 0 on success, -1 on error. Optional argument set count is used by semaphores.
reset <lockId> [reset count]
- returns 0 on success, -1 on error. Optional argument wait count is used by semaphores.
delete <lockId>
- returns 0 on success, -1 on error
close <lockId>

*Note* Using invalid lockId results to daemon crash.

Sample code:


set filename "c:/tcltest"
## Sample for synchronized file access using global lock
if { [catch { set fd [open $filename "RDWR CREAT"]}] == 0 } {
## Open wait object
if { [catch { set wo [waitobject open "my_global_lock" event true]}] == 0 } {
## Wait for wait object (5000ms)
if { [catch { set result [waitobject wait $wo 5000]}] == 0 && $result == 0 } {
## Do stuff...
iputs "$filename is now open & locked"
## Release wait object
waitobject set $wo
}
waitobject close $wo
}
close $fd
}

## Something more advanced; using semaphore to allow multiple simultanous reads on file
if { [catch { set fd [open $filename "RDWR CREAT"]}] == 0 } {
## Open wait object
if { [catch { set wo [waitobject open "my_semaphore" semaphore 1000]}] == 0 } {
## We want to read
if { [catch { set result [waitobject wait $wo 5000]}] == 0 && $result == 0 } {
## Do stuff...
iputs "$filename is now open, and locked for reads"
## Release wait object
waitobject set $wo
}
## Now we want to write
if { [catch { set wo2 [waitobject open "my_event" semaphore 1000]}] == 0 } {
if { [catch { set result [waitobject wait $wo2 5000]}] == 0 && $result == 0 } {
if { [catch { set result [waitobject wait $wo 5000 1000]}] == 0 && $result == 0 } {
iputs "$filename is now open, and locked for writes"
waitobject set $wo 1000
}
waitobject set $wo2
}
waitobject close $wo2
}
waitobject close $wo
}
close $fd
}
darkone is offline  
Old 11-17-2003, 11:45 AM   #2
b>d>>s
Senior Member
 
Join Date: Feb 2003
Posts: 488
Default

w0w0w0

thanks
b>d>>s is offline  
Closed Thread

Tags
$wo, open, set, wait, [catch

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 11:15 AM.

Parts of this site powered by vBulletin Mods & Addons from DragonByte Technologies Ltd. (Details)