Changes between Version 9 and Version 10 of FDORfc47
- Timestamp:
- 01/15/10 08:36:26 (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
FDORfc47
v9 v10 23 23 == Overview == 24 24 25 The !AddRef / Release / !GetRefCountmethods on FdoIDisposable are not currently thread-safe. As a consequence the m_refCount data member can get corrupted if two separate threads simultaneously call any of these methods on the same object. This is known to happen during garbage collection of Managed FDO objects. Because the managed objects implement a finalizer, they are processed by a separate GC finalizer thread. So while the GC finalizer thread is releasing ref counts on unmanaged objects, the main thread can be simultaneously modifying ref-counts on those same objects.25 The !AddRef and Release methods on FdoIDisposable are not currently thread-safe. As a consequence the m_refCount data member can get corrupted if two separate threads simultaneously call any of these methods on the same object. This is known to happen during garbage collection of Managed FDO objects. Because the managed objects implement a finalizer, they are processed by a separate GC finalizer thread. So while the GC finalizer thread is releasing ref counts on unmanaged objects, the main thread can be simultaneously modifying ref-counts on those same objects. 26 26 27 27 == Proposed Solution == 28 28 29 In !MapGuide th is issue is addressed by having all the unmanaged API classes extend from !MgGuardDisposable, which uses a mutex to limit access to the ref-count member to one thread at a time.29 In !MapGuide the refcount threading issue is addressed by having the refcounted classes extend from !MgGuardDisposable, which in turn uses a mutex to limit access to the refcount member variable to one thread at a time. A similar solution will be implemented for the FDO API, with a slight variation. On Linux, a mutex will be used. On Windows, the FDO API will use the !InterlockedIncrement and !InterlockedDecrement methods. 30 30 31 A similar solution will be implemented for the FDO API, with a slight variation. The FDO API will use !InterlockedIncrement and !InterlockedDecrement as opposed to a mutex. Also, the use of these thread safe functions will be limited to FDO objects that are wrapped by a Managed object wrapper. 31 On Windows, the use of thread safe functions will always be activated in case where unmanaged FDO objects are wrapped by a Managed object wrapper. Otherwise, API callers will have the option of setting a per-object or global flag that will activate thread-safe access of the reference count member variable. 32 32 33 33 Here are the detailed steps that will need to be taken to implement the solution: 34 34 35 * Add a flag to FdoIDisposable (Boolean member variable) to indicate if Interlocked support should be enabled for FDO disposable objects 36 * Add a virtual method on FdoIDispoable that will indicate if Interlocked access should be enabled. E.g. bool !EnableInterlocked() 37 * Add Interlocked calls to !AddRef and Release that will only be executed if the boolean flag set by !EnableInterlocked() is True. 38 * Change the Managed FDO API's MgFdoIDisposable class to call !EnableInterlocked whenever creating an FDO managed wrapper object around an FDO unmanaged object. 35 * Add a static flag to FdoIDisposable (Boolean) to indicate if thread locking support should be enabled for all disposable objects 36 * Add a local flag to FdoIDisposable (Boolean) to indicate if thread locking support should be enabled for this disposable objects 37 * Add a virtual method on FdoIDispoable that will allow callers to enable thread locking for this object. 38 * Add a static method on FdoIDispoable that will allow callers to enable thread locking for all disposable objects. 39 * Add thread locking calls to the implementation !AddRef and Release that will only be executed if one of the boolean flags defined above is True. 40 * Change the Managed FDO API's MgFdoIDisposable class to enable thread locking whenever creating an FDO managed wrapper object around an FDO unmanaged object. 39 41 40 42 This solution should provide thread safe access for clients using the FDO Managed API while allowing those who use the unmanaged FDO API directly to avoid the added overhead of Interlocked support.