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 | |
| 29 | When evaluating the inefficiencies, their impact should be considered in terms of their probability and overhead of the duplicated call. The duplicated case, |
| 30 | {{{ |
| 31 | 1. thread 1: if not foo: true, needs initializing |
| 32 | 2. thread 2: if not foo: true, needs initializing |
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): |
| 36 | is 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 | |
| 40 | Incomplete initialization problem is the following: |
| 41 | {{{ |
| 42 | foo = [] |
| 43 | |
| 44 | 1. thread 1: if not foo: true, needs initializing |
| 45 | 2. thread 1: foo.append(x) |
| 46 | 3. thread 2: if not foo: false, does not need initializing --> use the incomplete foo |
| 47 | 4. thread 1: foo.append(y) |
| 48 | 5. thread 2: use fully initialized foo |
| 49 | }}} |
| 50 | |
| 51 | Incomplete 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): |