home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / mac / database / 1788 < prev    next >
Encoding:
Text File  |  1993-01-24  |  1.6 KB  |  45 lines

  1. Newsgroups: comp.sys.mac.databases
  2. Path: sparky!uunet!wupost!psuvax1!news.cc.swarthmore.edu!ralph.cs.haverford.edu!eoliver
  3. From: eoliver@ralph.cs.haverford.edu (Erik Oliver)
  4. Subject: Re: 4D Field Incrementing
  5. Message-ID: <NB0WBWA2@cc.swarthmore.edu>
  6. Sender: news@cc.swarthmore.edu (USENET News System)
  7. Nntp-Posting-Host: ralph.cs.haverford.edu
  8. Organization: Haverford College Computer Science Department
  9. References: <1993Jan24.020602.20467@freenet.carleton.ca>
  10. Date: Sun, 24 Jan 1993 13:59:55 GMT
  11. Lines: 32
  12.  
  13. In article <1993Jan24.020602.20467@freenet.carleton.ca> aa192@Freenet.carleton.ca (Graydon Patterson) writes:
  14. >
  15. >Here is the standard procedure I use to create unique ID's..
  16. >`    NextID
  17. >$0:=[NextID]ID
  18. >[NextID]ID:=[NextID]ID+1
  19. >SAVE RECORD([NextID])
  20. >`    end script
  21. >
  22. >To obtain a unique ID in any file use the following...
  23. >[Clients]Client Number:=NextID    ` NEXTID being a function
  24. >
  25. >The NextIF file has only one field called ID and only one
  26. >record, the next ID to be called.
  27. >(pardon my typos)
  28. >-- 
  29. >
  30.  
  31. NO NO NO NO NO.  What if this was a multi-user database, what if lots of
  32. people all over the world tried to get a new ID simultaneously, two
  33. people might both assing $0 := [NextID]ID, and both might get the exact
  34. same value before raising the value of [NextID]ID, in Comp. Sci. terms,
  35. you have a _race condition_.
  36.  
  37. If you feel the need to use this solution, turn this procedure into a
  38. TRANSACTION, or use the SEMAPHORE features of 4D to protect against this
  39. happening.
  40.  
  41. But, if you really need Unique IDs, NEVER NEVER NEVER use the above
  42. procedure in a multi-user database, or even in a single user databse
  43.  
  44. -Erik
  45.