Overview
| Artifact ID: | 51847a2a1af0f27f5c05b674a37d495fb9941342f455bf57f112a42ef751c5a9 |
|---|---|
| Ticket: | 4f322b9d2112772a4a9599611def6e651f8e5198
Impossibility to create an unique path in Tcl (e. g. using file mkdir) |
| User & Date: | sebres on 2018-07-02 12:12:33 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-fossil-wiki"
- comment changed to:
If working multi-threaded (or multi-processed in cluster-system on share) with some global directory to create some system-wide unique sub-path using some pseudo-unique name generation algorithm (also UUID), to avoid retrieving of the same folder for two workers, one can do the things like this: <code><pre style="padding-left:10pt"> proc get_unique_dir {} { while 1 { set p [file join $GLOB_PATH [some_uuid_algo]] if {![file exists $p]} { file mkdir $p break } } return $p } </pre></code> But it's affected by the race condition (firstly not exists for both workers, then one creates sub-path, another returns with no error in `file mkdir` on same existing path), if some_uuid_algo cannot guarantee a system-wide unique path. So the creation of a safe construct for that is impossible in Tcl currently. <b>Suggestion:</b> Currently `file mkdir` returns no result at all. <br/> If `TclFileMakeDirsCmd` will be extended with return value as counter (of created <b>tail</b>-directories), one may use it to avoid race condition in above-mentioned script, like here: <code><pre style="padding-left:10pt"> proc get_unique_dir {} { while 1 { set p [file join $GLOB_PATH [some_uuid_algo]] if {[file mkdir $p]} { break } } return $p } </pre></code> This is race condition safe. The only one backwards-incompatibility in this case would be usage like this: <code><pre style="padding-left:10pt"> set some_var "when [file mkdir $some_path]was used in substitution" </pre></code> But I believe the way like this is very rarely (or almost never) used. - foundin changed to: ">= 8.5"
- is_private changed to: "0"
- login: "sebres"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "sebres"
- subsystem changed to: "16. Commands A-H"
- title changed to:
Impossibility to create an unique path in Tcl (e. g. using file mkdir)
- type changed to: "RFE"