On 21/01/2015 17:28, Jiri Slaby wrote:
> +        if (atomic_fetch_or(&edu->status, EDU_STATUS_COMPUTING) & 
> EDU_STATUS_COMPUTING) {

Theoretically the other thread could see EDU_STATUS_COMPUTING here and
not enter the condvar wait.  So...

> +            break;
> +        }
> +        qemu_mutex_lock(&edu->thr_mutex);
> +        edu->fact = val;
> +        qemu_cond_signal(&edu->thr_cond);
> +        qemu_mutex_unlock(&edu->thr_mutex);

... just one change:

   if (atomic_read(&edu->status) & EDU_STATUS_COMPUTING) {
       break;
   }
   /* EDU_STATUS_COMPUTING cannot go 0->1 concurrently, because
    * it is only set in this function and it is under the iothread
    * mutex.
    */
   qemu_mutex_lock(&edu->thr_mutex);
   edu->fact = val;
   atomic_or(&edu->status), EDU_STATUS_COMPUTING);
   qemu_cond_signal(&edu->thr_cond);
   qemu_mutex_unlock(&edu->thr_mutex);

If you are okay with this change, I'll apply the patch to my tree.

Paolo

Reply via email to