Re: [Lse-tech] Re: multi-queue scheduler update

Davide Libenzi (davidel@xmail.virusscreen.com)
Fri, 19 Jan 2001 15:24:41 -0800


On Friday 19 January 2001 15:23, Mike Kravetz wrote:
> On Fri, Jan 19, 2001 at 02:03:06PM -0800, Davide Libenzi wrote:
> <stuff deleted>
>
> > > void oneatwork(int thr)
> > > {
> > > int i;
> > > while (!start) /* don't disturb pthread_create() */
> > > usleep(10000);
> > >
> > > actthreads++;
> > > while (!stop)
> > > {
> > > if (count)
> > > totalwork[thr]++;
> > >
> > > syscall(158); /* sys_sched_yield() */
> > > }
> > > actthreads--;
> > > pthread_exit(0);
> > > }
> > >
> > > Note that actthreads is a global variable which is being updated
> > > by multiple threads without any form of synchronization. Because
> > > of this actthreads sometimes never goes to zero after all worker
> > > threads have finished.
> >
> > If all threads complete successfully actthreads has to be zero.
>
> Not as currently coded. If two threads try to decrement actthreads
> at the same time, there is no guarantee that it will be decremented
> twice. That is why you need to put some type of synchronization in
> place.

Right, inc & dec are not atomic w/o #LOCK.

- Davide
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/