Isabelle_System.mk_fifo: more robust enumeration of unique names, based on persisting JVM pid (parent of shell process);
--- a/lib/Tools/mkfifo Sat Sep 18 17:14:47 2010 +0200
+++ b/lib/Tools/mkfifo Sat Sep 18 17:39:23 2010 +0200
@@ -10,7 +10,7 @@
function usage()
{
echo
- echo "Usage: isabelle $PRG"
+ echo "Usage: isabelle $PRG [SUFFIX]"
echo
echo " Create a temporary named pipe and return its name."
echo
@@ -26,10 +26,12 @@
## main
+SUFFIX=""
+[ "$#" != 0 ] && { SUFFIX="-$1"; shift; }
+
[ "$#" != 0 ] && usage
-#FIXME potential race condition wrt. future processes with same pid
-FIFO="/tmp/isabelle-fifo$$"
+FIFO="/tmp/isabelle-fifo${PPID}${SUFFIX}"
mkfifo -m 600 "$FIFO" || fail "Failed to create fifo: $FIFO"
echo "$FIFO"
--- a/src/Pure/System/isabelle_system.scala Sat Sep 18 17:14:47 2010 +0200
+++ b/src/Pure/System/isabelle_system.scala Sat Sep 18 17:39:23 2010 +0200
@@ -273,9 +273,16 @@
/* named pipes */
+ private var fifo_count: Long = 0
+ private def next_fifo(): String = synchronized {
+ require(fifo_count < java.lang.Long.MAX_VALUE)
+ fifo_count += 1
+ fifo_count.toString
+ }
+
def mk_fifo(): String =
{
- val (result, rc) = isabelle_tool("mkfifo")
+ val (result, rc) = isabelle_tool("mkfifo", next_fifo())
if (rc == 0) result.trim
else error(result)
}