Create a unique name

[Autolink] Menu

There are 2 methods to create unique names for programs running at the same time in two or more sessions:

1. Using a directory name

 
/* example code to show how to use a directory name to get a unique   */
/* name                                                               */

  uniqueName = ""
  do i = 1 to 999 until rc = 0
    uniqueName = "C:\TEMP\unique." || i
                                /* try to create a directory          */
                                /* OS/2 checks that only ONE process  */
                                /* can create the directory!          */
    "@md " uniqueName "1>NUL 2>NUL"
  end /* do i = 1 to 999 */

  if rc == 0 then
    say "The unique name is" uniqueName
  else
    say "No unique name found!"

/* do something */
/* ... */
                                /* free the name                      */
  "@rd " uniqueName "1>NUL 2>NUL"
exit 0

2. Using the name of a QUEUE

 
/* example code to show how to use a queue name to get a unique       */
/* name                                                               */

                                /* create a queue with a unique name  */
  uniqueName = rxqueue( "create" )

  say "The unique name is" uniqueName

/* do something */
/* ... */
                                /* free the name                      */
  call rxqueue "Delete", uniqueName
exit 0


[Back: IPC and process synchronisation]
[Next: Simulate a semaphore]