Home > Software engineering >  Multi-threaded memory pool safety, the eldest brother is how lock?
Multi-threaded memory pool safety, the eldest brother is how lock?

Time:11-16

I wrote a single thread pool class, because it is a block of memory structure, take the time is fast, faster recovery,
But I can't think of at the time of multithreading safety, what's safe and fast,
I have my own ideas:
First, each small plus lock, slow, and I add is atomic lock InterlockedExchange
Second, each small pieces plus the critical section, I depend, more slowly,
Third: each small pieces and critical region, but use the Try critical region, slower than the atomic locks
Article 4: each memory pool with critical region, a small piece of memory don't need, speed test, should be faster than every small lock


In fact, I think every small piece with lock, means to think if there is a piece of memory can be recycled, there are 5 thread is about to visit, because the small piece of memory is being recycled access, so this article 5 threads will not be blocked, skip, so as not to happen each thread is waiting for, or if there are 40 threads need to remove the memory, at the same time have stuck here, efficiency is slow, but still a little slow,

I thought it is
The lock ();
Alloc ()//in directly by intersection of the memory block with locks, but I don't know this speed?
Unlock ();

Everyone a great god, and to the point of views, the multithreading safety, the lock is how do you use?
  • Related