Skip to main content
added 513 characters in body
Source Link
Ben Aston
  • 56k
  • 69
  • 221
  • 351

I am writing a system for automatically recalculating the results of costly methods, and then storing them in a cache. The cache may be distributed, meaning (obviously) multiple processes can access it.

On the first invocation of the method to cache the result for, I want to spawn a thread that will periodically recalculate the result of the method and update the cache.

I want only a single thread of execution to be spawned per cache item. In a multi-process environment, can this be achieved using a cross process mutex such as this?

http://msdn.microsoft.com/en-us/library/system.threading.mutex.aspx

Are there any pitfalls with this approach?

Edit:

Truth table for my implementation:

// in-cache | mutex-found // 0 0 //not in cache, no mutex; start thread // 1 0 //in cache, no mutex; assume thread already started (re-calculating thread could be in another process) // 0 1 //not in cache, mutex found; thread started, do not start thread - log error (and possibly start new thread) // 1 1 //in cache, mutex found; thread started, do not start thread 

I am writing a system for automatically recalculating the results of costly methods, and then storing them in a cache. The cache may be distributed, meaning (obviously) multiple processes can access it.

On the first invocation of the method to cache the result for, I want to spawn a thread that will periodically recalculate the result of the method and update the cache.

I want only a single thread of execution to be spawned per cache item. In a multi-process environment, can this be achieved using a cross process mutex such as this?

http://msdn.microsoft.com/en-us/library/system.threading.mutex.aspx

Are there any pitfalls with this approach?

I am writing a system for automatically recalculating the results of costly methods, and then storing them in a cache. The cache may be distributed, meaning (obviously) multiple processes can access it.

On the first invocation of the method to cache the result for, I want to spawn a thread that will periodically recalculate the result of the method and update the cache.

I want only a single thread of execution to be spawned per cache item. In a multi-process environment, can this be achieved using a cross process mutex such as this?

http://msdn.microsoft.com/en-us/library/system.threading.mutex.aspx

Are there any pitfalls with this approach?

Edit:

Truth table for my implementation:

// in-cache | mutex-found // 0 0 //not in cache, no mutex; start thread // 1 0 //in cache, no mutex; assume thread already started (re-calculating thread could be in another process) // 0 1 //not in cache, mutex found; thread started, do not start thread - log error (and possibly start new thread) // 1 1 //in cache, mutex found; thread started, do not start thread 
edited tags
Link
Reinderien
  • 16.7k
  • 9
  • 56
  • 93
There instead of their.
Source Link
Manoj Govindan
  • 75.2k
  • 21
  • 138
  • 142

I am writing a system for automatically recalculating the results of costly methods, and then storing them in a cache. The cache may be distributed, meaning (obviously) multiple processes can access it.

On the first invocation of the method to cache the result for, I want to spawn a thread that will periodically recalculate the result of the method and update the cache.

I want only a single thread of execution to be spawned per cache item. In a multi-process environment, can this be achieved using a cross process mutex such as this?

http://msdn.microsoft.com/en-us/library/system.threading.mutex.aspx

Are theirthere any pitfalls with this approach?

I am writing a system for automatically recalculating the results of costly methods, and then storing them in a cache. The cache may be distributed, meaning (obviously) multiple processes can access it.

On the first invocation of the method to cache the result for, I want to spawn a thread that will periodically recalculate the result of the method and update the cache.

I want only a single thread of execution to be spawned per cache item. In a multi-process environment, can this be achieved using a cross process mutex such as this?

http://msdn.microsoft.com/en-us/library/system.threading.mutex.aspx

Are their any pitfalls with this approach?

I am writing a system for automatically recalculating the results of costly methods, and then storing them in a cache. The cache may be distributed, meaning (obviously) multiple processes can access it.

On the first invocation of the method to cache the result for, I want to spawn a thread that will periodically recalculate the result of the method and update the cache.

I want only a single thread of execution to be spawned per cache item. In a multi-process environment, can this be achieved using a cross process mutex such as this?

http://msdn.microsoft.com/en-us/library/system.threading.mutex.aspx

Are there any pitfalls with this approach?

Source Link
Ben Aston
  • 56k
  • 69
  • 221
  • 351
Loading