Could this cause multiple identical GUIDs?

前端 未结 4 1001
耶瑟儿~
耶瑟儿~ 2021-01-17 19:32

As GUID generation is time-dependent, if System.Guid.NewGuid() is called multiple times at the exact same instant on different threads, could it return identical GUIDs?

相关标签:
4条回答
  • 2021-01-17 20:16

    Unless your threads are running on different cores on your machine, only one thread will be actually running at a given time. Hence, I do not think it is very likely that calls to NewGuid() will take place at the exact same time.

    0 讨论(0)
  • 2021-01-17 20:24

    No, there is a serial number inside it that changes for each call, so multiple simultaneous calls on different threads on the same system will not create duplicate Guids.

    That does not mean that there is a visible part of the Guid that you can see increments for each call.

    0 讨论(0)
  • 2021-01-17 20:28

    On Windows, GUIDs (UUIDs) are created from a cryptographic random number generator with UuidCreate. They are version 4 UUIDs in terms of RFC 4122. No timestamps or ethernet cards are involved, unless you're using old school version 1 GUIDs created with UuidCreateSequential.

    See also How Random is System.Guid.NewGuid()? (Take two)

    0 讨论(0)
  • 2021-01-17 20:30

    The Transact-SQL NEWID function and the application API functions and methods generate new uniqueidentifier values from the identification number of their network card plus a unique number from the CPU clock. Each network card has a unique identification number. The uniqueidentifier value that is returned by NEWID is generated by using the network card on the server. The uniqueidentifier value returned by application API functions and methods is generated by using the network card on the client.

    .It wont generate duplicates in time or in any pc as per msdn.

    0 讨论(0)
提交回复
热议问题