Changes between Version 22 and Version 23 of DjangoSpecifications/Core/Threading


Ignore:
Timestamp:
04/15/2008 09:49:11 AM (7 years ago)
Author:
mrts
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DjangoSpecifications/Core/Threading

    v22 v23  
    2525 * errors due to incomplete initialization.
    2626
    27 When evaluating the inefficiencies, their impact should be considered in terms of their probability and the overhead of duplicated call. The worst case,
    28 {{{
    29 1. thread 1: if not foo: needs initializing
    30 2. thread 2: if not foo: needs initializing
     27=== Inefficiencies ===
     28
     29When evaluating the inefficiencies, their impact should be considered in terms of their probability and overhead of the duplicated call. The duplicated case,
     30{{{
     311. thread 1: if not foo: true, needs initializing
     322. thread 2: if not foo: true, needs initializing
    31333. thread 1: initialize foo
    32344. thread 2: initialize foo
    3335}}}
    34 is not that common and there are no large initialization overhead cases below, so the "inefficiency issues" are really non-issues. There is at least one bug though.
    35 
    36 Incomplete initialization errors can generally be avoided by using full assignment instead of elementwise modification (that's how it is done in the source mostly):
     36is not that common. No code where duplicated call would cause a considerable overhead or harmful side-effects was found during the review, so '''the "inefficiency issues" are really non-issues''' and listed below only for reference.
     37
     38=== Errors due to incomplete initialization ===
     39
     40Incomplete initialization problem is the following:
     41{{{
     42foo = []
     43
     441. thread 1: if not foo: true, needs initializing
     452. thread 1: foo.append(x)
     463. thread 2: if not foo: false, does not need initializing --> use the incomplete foo
     474. thread 1: foo.append(y)
     485. thread 2: use fully initialized foo
     49}}}
     50
     51Incomplete initialization errors can generally be avoided by using full assignment instead of elementwise modification; additionally, to make sure no further modifications of a list can happen, tuples should be used instead of lists (inspired by source:django/trunk/django/template/context.py#L86):
    3752
    3853'''BAD'''
     
    5873      foo = tuple(tmp) # assignment is "atomic", tuple is const-correct and more efficient
    5974}}}
     75
     76There is at least one location in code that uses the "bad" algorithm.
    6077
    6178=== Modules' use of globals ===
Back to Top