views:

178

answers:

1

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%28VS.85%29.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?

+1  A: 

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.

bobbymcr