Task locks ??

From: Matthias Urlichs (smurf@noris.net)
Date: Thu May 11 2000 - 06:41:12 EST


Hi,

I womder what this patch (from 2.3.99.pre7.8 => 7.9) is supposed to
accomplish. perhaps somebody can enlighten me..?

drivers/char/tty_io.c: ... if(...!current->tty...) {

+ task_lock(current);
        current->tty = tty;
+ task_unlock(current);
        current->tty_old_pgrp = 0;

Since reads of current->tty are not locked, I fail to see any reason for
this change.

Same question, only worse, with this changed code (kernel/exit.c):

+ struct files_struct * files = tsk->files;
 
        if (files) {
+ task_lock(tsk);
+ tsk->files = NULL;
+ task_unlock(tsk);
+ put_files_struct(files);
        }

If two threads really can run this code at the same time, the locks
don't help. If not, they're unnecessary.

Better code:

        task_lock(tsk);
 
        if (tsk->files) {
                struct files_struct * files = tsk->files;
                tsk->files = NULL;
                task_unlock(tsk);
                put_files_struct(files);
        } else
                task_unlock(tsk);

or, since put_files_struct really doesn't take long and the additional
complexity is unnecessary, simply

        task_lock(tsk);
        if (tsk->files) {
                put_files_struct(tsk->files);
                tsk->files = NULL;
        }
        task_unlock(tsk);

Comments?

-- 
Matthias Urlichs  |  noris network GmbH   |   smurf@noris.de  |  ICQ: 20193661
The quote was selected randomly. Really.       |        http://smurf.noris.de/
-- 
The only solution is...a balance of power.  We arm our side with exactly that
much more.  A balance of power -- the trickiest, most difficult, dirtiest game
of them all.  But the only one that preserves both sides.
                        -- Kirk, "A Private Little War," stardate 4211.8

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



This archive was generated by hypermail 2b29 : Mon May 15 2000 - 21:00:17 EST