Multithreading cache

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Multithreading cache

      Hello !

      I'm just about finished designing my resource-cache-manager, and I kinda got stuck when thinking about multithreading:

      I have multiple threads in my engine.. each possibly requesting cache items anytime throughout the play... Now my "CCacheItem" class is a bit complex and it will not support nicelly if 2 threads call some member functions simultaneously.

      So.. I began wondering.. is there a big (performance-wise) penalty for declaring a mutex for each cache resource? about ~500 items at one time..

      The alternative would be to have 1 mutex for the cache manager's "GET" function. But then I can only serve 1 item from the cache which is a bit beyond the scope of having this complex structure in the first place...

      Any ideeas?
      Quisquis latium dictio gravis videre
    • IIRC,

      Using CriticalSectiions will be more efficient if your synchronization is all in-process.

      Mutexes and Semaphores are kernel-objects, and thus require more code to run to operate.

      Critical Sections are single-process objects and so only affect the threads of a single process.