Re: [PATCH 4/6] kvm tools: Add rwlock wrapper

Ingo Molnar
2011-05-28T15:24:20Z

* Sasha Levin <levinsasha928@gmail.com> wrote:

> So the basic plan here is to allocate a futex(?) for each VCPU
> thread, and have the writer thread lock all futexes when it needs
> to write?
>
> If we assume we only have one writer thread, it can stay pretty
> simple.

We can use an even simpler and more scalable method:

- writers can 'stop' all other threads, by sending them a
threadpool signal and waiting for each thread to have completed
processing their current work and notifying the writer back that
they have stopped running.

This means that the read-side lock is _zero instructions_, basically
just a barrier() to make sure the compiler does not move instructions
across threadpool functions (it wont).

This method requires that we know about every worker thread - i.e.
no-one does a stray pthread_create() and uses data structures from
there. It also requires that each worker thread can 'stop' within a
reasonable amount of time.

Thanks,

Ingo