UuidCreateSequential 和 p/invoke 调用的线程安全性
我正在使用一个使用 GUID 作为大多数数据库表中的键的系统。 guid 是使用 UuidCreateSequential 创建的,以便更好地处理数据库索引。
C++ 语法,根据 http://msdn.microsoft。 com/en-us/library/aa379322(VS.85).aspx :
RPC_STATUS RPC_ENTRY UuidCreateSequential(
UUID __RPC_FAR *Uuid
);
p/invoke.net 建议使用以下签名:
[DllImport("rpcrt4.dll", SetLastError=true)]
static extern int UuidCreateSequential(out Guid guid);
问题是 - 我如何知道此方法是否可以安全地同时从多个线程调用?初步测试表明这可能是安全的,但我在 MSDN 或 Google 上没有找到任何与此相关的重要信息。对于我可以依赖的 Windows API 调用,是否有任何标准约定?
I am working with a system that uses GUIDs as keys in most database tables. The guids are created using UuidCreateSequential, in order to be nice to the database indexes.
C++ syntax, according to http://msdn.microsoft.com/en-us/library/aa379322(VS.85).aspx :
RPC_STATUS RPC_ENTRY UuidCreateSequential(
UUID __RPC_FAR *Uuid
);
p/invoke.net suggests the following signature:
[DllImport("rpcrt4.dll", SetLastError=true)]
static extern int UuidCreateSequential(out Guid guid);
The question is - how can I know whether this method is safe to invoke from several threads simultaneously? Initial tests show that this might be safe, but I haven't found any significant information regarding this on MSDN or Google. Is there any standard convention regarding calls to the windows API that I can rely on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常可以安全地假设大多数 Windows API 都是线程安全的。
应该能够随时从系统上的任何应用程序创建全局唯一 ID。因此我认为线程安全是 GUID 生成器的必需功能。 RFC 4122 描述了一种生成 GUID 的方法,该方法应该与 Windows 实际执行的操作相当接近。请注意,它提到获取全局锁,这是确保同时调用创建 GUID 无法获取相同值所必需的。
It's generally safe to assume that most of the Windows API is thread-safe.
A globally unique ID should be able to be created from any application on the system at any time. Therefore I would say thread-safety is a required feature of a GUID generator. RFC 4122 describes a method for generating GUIDs which should be fairly close to what Windows actually does. Note that it mentions obtaining a global lock which would be necessary to ensure simultaneous calls to create a GUID cannot get the same value.