[CRIU] Re: [PATCH 23/24] zdtm: Add task_waiter_ helpers v2

Cyrill Gorcunov gorcunov at openvz.org
Tue Jun 19 02:11:45 EDT 2012


On Tue, Jun 19, 2012 at 08:52:12AM +0400, Andrew Vagin wrote:
> > +void task_waiter_wait(task_waiter_t *t)
> > +{
> > +	struct timespec req = { .tv_nsec = TASK_WAITER_INITIAL, };
> > +	struct timespec rem = { };
> > +	int v, attempts = 5;
> > +
> > +	for (;;) {
> > +		if (!attempts--) {
> > +			errno = EAGAIN;
> > +			goto err;
> > +		}
> > +		if (read(t->pipes[0], &v, sizeof(v)) !=  sizeof(v))
> > +			goto err;
> ----------------------------------------------
> > +		if (v != t->raw + 1) {
> > +			if (write(t->pipes[1], &v, sizeof(v)) !=  sizeof(v))
> > +				goto err;
> > +			nanosleep(&req, &rem);
> > +			req.tv_nsec += t->seed;
> > +		} else {
> > +			t->raw++;
> > +			break;
> > +		}
> ----------------------------------------------
> Pls explain this part.

There could be a situation when a child process receives value not intended
for him, in this case the child should write such value back and wait a
bit to eliminate contention.

For example

  parent             child 1                         child 2
  ------             -----------                     ---------
  writes 2           waits for 1                     waits for 2
                     reads 1
                     finds the value is unexpected
                     write it back
                     and wait for some time
                                                     reads 2

Or I miss something?

	Cyrill


More information about the CRIU mailing list