lkml.org 
[lkml]   [2000]   [Oct]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: set_current_state() vs current->state
On Sun, Oct 01, 2000 at 03:04:31AM -0400, Frank Davis wrote:
> Hello all,
> I've been going through the drivers/block code (almost done) and noticed the use of, eg.:
> set_current_state(TASK_RUNNING); and also
> current->state = TASK_RUNNING;
>
> Which one is most recent, and is there a suggestion on which one to use?

`__set_current_state(x)' is completly equivalent to `current->state = x'.

set_current_state(x) instead means:

current->state = x
mb()

It puts a CPU memory barrier _after_ the assignment. This is necessary in most
cases while using the wait-event interface to avoid SMP races.

In short you need set_current_state(x) when you do something that relies on the
ordering like:

set_current_state(TASK_UNINTERRUPTIBLE)
if (event_happened_meanwhile)
break;
schedule();

You must make sure not to read `event_happened_meanwhile' before making visible
the change of current->state to avoid missing one event and to hang in
UNINTERRUPTIBLE mode in schedule.

You don't need the mb() version (so you can use __set_current_state(x)) when
you do something that doesn't relies on the ordering like:

[..]
remove_wait_queue(...);
__set_current_state(TASK_RUNNING);
return;

In the l-k archives you should find further details of such SMP race conditions.

Andrea
-
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/

\
 
 \ /
  Last update: 2005-03-22 12:39    [W:0.030 / U:9.228 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site