com - Is it possible to dictate use of RPC callback threads? -


i working on bug related unmanaged mta com object. object has lock , unlock methods , uses mutex requires same thread called lock call unlock.

the problem when lock , unlock called managed sta thread (using com interop), calls come com object on rpc callback thread callback thread used not same both calls. when not same, unlock call fails because can't unlock mutex.

in other words:

managed sta thread 1 -> rpc callback (thread 11) -> lock

managed sta thread 1 -> rpc callback (thread 12) -> unlock -> error

i trying evaluate possible solutions before making decisions on fix. such, trying find out:

1) there way prevent rpc callback thread being used in first place? in testing, if make calls object unmanaged sta thread, calls seem come in on calling thread itself. different when call coming .net necessitates use of rpc callback thread? there way prevent rpc callbacks being used? (except using mta calling thread)

2) if not, there way force consistent rpc callback thread used same managed sta thread?

this design free-threaded server. com takes word , allows stubs use arbitrary rpc threads. cannot make assumptions thread identity, rpc thread picked pool , recycled. unfortunately picks same 1 when calls sequenced works fine @ first. trouble starts more 1 concurrent server call made. there no option make selective, free-threaded server promises not care. nor work in practice, either scale horribly or induce deadlock.

you therefore cannot use mutex implement locking, has thread affinity. semaphore choice.


Comments