"Dr. David Alan Gilbert" <[email protected]> wrote: > * Peter Xu ([email protected]) wrote: >> On Wed, Jul 19, 2017 at 08:02:39PM +0100, Dr. David Alan Gilbert wrote: >> ... here can we just do this? >> >> retry: >> // don't take any lock, only read each p->address >> for (i = 0; i < multifd_send_state->count; i++) { >> p = &multifd_send_state->params[i]; >> if (!p->address) { >> // we found one IDLE send thread >> break; >> } >> } >> if (!p) { >> qemu_sem_wait(&multifd_send_state->sem); >> goto retry; >> } >> // we switch its state, IDLE -> ACTIVE >> atomic_set(&p->address, address); >> // tell the thread to start work >> qemu_sem_post(&p->sem); >> >> Above didn't really use any lock at all (either the per thread lock, >> or the global lock). Would it work? > > I think what's there can certainly be simplified; but also note > that the later patch gets rid of 'address' and turns it into a count. > My suggest was to keep the 'done' and stop using 'address' as something > special; i.e. never write address in the thread; but I think yours might > work as well.
I substitute the test from address == 0 to page.num == 0. Notice that this is temporal, just to check that I am doing the things right. we end sending the pages here. Later, Juan.
