<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
software	B-Operating_System
transactional	I-Operating_System
memory	I-Operating_System
(	O
STM	O
)	O
is	O
a	O
concurrency	B-Operating_System
control	I-Operating_System
mechanism	O
analogous	O
to	O
database	B-General_Concept
transactions	I-General_Concept
for	O
controlling	O
access	O
to	O
shared	B-Operating_System
memory	I-Operating_System
in	O
concurrent	B-Architecture
computing	I-Architecture
.	O
</s>
<s>
It	O
is	O
an	O
alternative	O
to	O
lock-based	B-Operating_System
synchronization	I-Operating_System
.	O
</s>
<s>
A	O
transaction	O
in	O
this	O
context	O
occurs	O
when	O
a	O
piece	O
of	O
code	O
executes	O
a	O
series	O
of	O
reads	O
and	O
writes	O
to	O
shared	B-Operating_System
memory	I-Operating_System
.	O
</s>
<s>
In	O
1995	O
Nir	O
Shavit	O
and	O
Dan	O
Touitou	O
extended	O
this	O
idea	O
to	O
software-only	O
transactional	B-Operating_System
memory	I-Operating_System
(	O
STM	O
)	O
.	O
</s>
<s>
Unlike	O
the	O
locking	B-Operating_System
techniques	O
used	O
in	O
most	O
modern	O
multithreaded	O
applications	O
,	O
STM	O
is	O
often	O
very	O
optimistic	B-Operating_System
:	O
a	O
thread	B-Operating_System
completes	O
modifications	O
to	O
shared	B-Operating_System
memory	I-Operating_System
without	O
regard	O
for	O
what	O
other	O
threads	B-Operating_System
might	O
be	O
doing	O
,	O
recording	O
every	O
read	O
and	O
write	O
that	O
it	O
is	O
performing	O
in	O
a	O
log	O
.	O
</s>
<s>
Instead	O
of	O
placing	O
the	O
onus	O
on	O
the	O
writer	O
to	O
make	O
sure	O
it	O
does	O
not	O
adversely	O
affect	O
other	O
operations	O
in	O
progress	O
,	O
it	O
is	O
placed	O
on	O
the	O
reader	O
,	O
who	O
after	O
completing	O
an	O
entire	O
transaction	O
verifies	O
that	O
other	O
threads	B-Operating_System
have	O
not	O
concurrently	O
made	O
changes	O
to	O
memory	O
that	O
it	O
accessed	O
in	O
the	O
past	O
.	O
</s>
<s>
The	O
benefit	O
of	O
this	O
optimistic	B-Operating_System
approach	O
is	O
increased	O
concurrency	B-Architecture
:	O
no	O
thread	B-Operating_System
needs	O
to	O
wait	O
for	O
access	O
to	O
a	O
resource	O
,	O
and	O
different	O
threads	B-Operating_System
can	O
safely	O
and	O
simultaneously	O
modify	O
disjoint	O
parts	O
of	O
a	O
data	O
structure	O
that	O
would	O
normally	O
be	O
protected	O
under	O
the	O
same	O
lock	O
.	O
</s>
<s>
Theoretically	O
,	O
the	O
worst	B-General_Concept
case	I-General_Concept
space	O
and	O
time	O
complexity	O
of	O
n	O
concurrent	O
transactions	O
is	O
O(n )	O
.	O
</s>
<s>
Actual	O
needs	O
depend	O
on	O
implementation	O
details	O
(	O
one	O
can	O
make	O
transactions	O
fail	O
early	O
enough	O
to	O
avoid	O
overhead	O
)	O
,	O
but	O
there	O
will	O
also	O
be	O
cases	O
,	O
albeit	O
rare	O
,	O
where	O
lock-based	O
algorithms	O
have	O
better	O
time	O
complexity	O
than	O
software	B-Operating_System
transactional	I-Operating_System
memory	I-Operating_System
.	O
</s>
<s>
Locking	B-Operating_System
requires	O
thinking	O
about	O
overlapping	O
operations	O
and	O
partial	O
operations	O
in	O
distantly	O
separated	O
and	O
seemingly	O
unrelated	O
sections	O
of	O
code	O
,	O
a	O
task	O
which	O
is	O
very	O
difficult	O
and	O
error-prone	O
.	O
</s>
<s>
Locking	B-Operating_System
requires	O
programmers	O
to	O
adopt	O
a	O
locking	B-Operating_System
policy	O
to	O
prevent	O
deadlock	B-Operating_System
,	O
livelock	B-Application
,	O
and	O
other	O
failures	O
to	O
make	O
progress	O
.	O
</s>
<s>
Locking	B-Operating_System
can	O
lead	O
to	O
priority	B-Operating_System
inversion	I-Operating_System
,	O
a	O
phenomenon	O
where	O
a	O
high-priority	O
thread	B-Operating_System
is	O
forced	O
to	O
wait	O
for	O
a	O
low-priority	O
thread	B-Operating_System
holding	O
exclusive	O
access	O
to	O
a	O
resource	O
that	O
it	O
needs	O
.	O
</s>
<s>
In	O
contrast	O
,	O
the	O
concept	O
of	O
a	O
memory	B-Operating_System
transaction	I-Operating_System
is	O
much	O
simpler	O
,	O
because	O
each	O
transaction	O
can	O
be	O
viewed	O
in	O
isolation	O
as	O
a	O
single-threaded	B-Operating_System
computation	O
.	O
</s>
<s>
Deadlock	B-Operating_System
and	O
livelock	B-Application
are	O
either	O
prevented	O
entirely	O
or	O
handled	O
by	O
an	O
external	O
transaction	O
manager	O
;	O
the	O
programmer	O
need	O
hardly	O
worry	O
about	O
it	O
.	O
</s>
<s>
Priority	B-Operating_System
inversion	I-Operating_System
can	O
still	O
be	O
an	O
issue	O
,	O
but	O
high-priority	O
transactions	O
can	O
abort	O
conflicting	O
lower	O
priority	O
transactions	O
that	O
have	O
not	O
already	O
committed	O
.	O
</s>
<s>
In	O
Haskell	B-Language
,	O
this	O
limitation	O
is	O
enforced	O
at	O
compile	O
time	O
by	O
the	O
type	O
system	O
.	O
</s>
<s>
In	O
2005	O
,	O
Tim	O
Harris	O
,	O
Simon	O
Marlow	O
,	O
Simon	O
Peyton	O
Jones	O
,	O
and	O
Maurice	O
Herlihy	O
described	O
an	O
STM	O
system	O
built	O
on	O
Concurrent	B-Language
Haskell	I-Language
that	O
enables	O
arbitrary	O
atomic	O
operations	O
to	O
be	O
composed	O
into	O
larger	O
atomic	O
operations	O
,	O
a	O
useful	O
concept	O
impossible	O
with	O
lock-based	O
programming	O
.	O
</s>
<s>
For	O
example	O
,	O
consider	O
a	O
hash	O
table	O
with	O
thread-safe	O
insert	O
and	O
delete	O
operations	O
.	O
</s>
<s>
Now	O
suppose	O
that	O
we	O
want	O
to	O
delete	O
one	O
item	O
A	O
from	O
table	O
t1	O
,	O
and	O
insert	O
it	O
into	O
table	O
t2	O
;	O
but	O
the	O
intermediate	O
state	O
(	O
in	O
which	O
neither	O
table	O
contains	O
the	O
item	O
)	O
must	O
not	O
be	O
visible	O
to	O
other	O
threads	B-Operating_System
.	O
</s>
<s>
This	O
scheme	O
has	O
been	O
implemented	O
in	O
the	B-Application
Glasgow	I-Application
Haskell	I-Application
Compiler	I-Application
.	O
</s>
<s>
This	O
loose	B-Application
coupling	I-Application
between	O
producers	O
and	O
consumers	O
enhances	O
modularity	O
compared	O
to	O
explicit	O
signaling	O
between	O
threads	B-Operating_System
.	O
</s>
<s>
"	O
Composable	B-Operating_System
Memory	I-Operating_System
Transactions	I-Operating_System
"	O
took	O
this	O
a	O
step	O
farther	O
with	O
its	O
retry	O
command	O
(	O
discussed	O
above	O
)	O
,	O
which	O
can	O
,	O
at	O
any	O
time	O
,	O
abort	O
the	O
transaction	O
and	O
wait	O
until	O
some	O
value	O
previously	O
read	O
by	O
the	O
transaction	O
is	O
modified	O
before	O
retrying	O
.	O
</s>
<s>
In	O
"	O
Composable	B-Operating_System
Memory	I-Operating_System
Transactions	I-Operating_System
"	O
,	O
the	O
authors	O
decided	O
that	O
this	O
should	O
abort	O
the	O
transaction	O
,	O
since	O
exceptions	O
normally	O
indicate	O
unexpected	O
errors	O
in	O
Concurrent	B-Language
Haskell	I-Language
,	O
but	O
that	O
the	O
exception	O
could	O
retain	O
information	O
allocated	O
by	O
and	O
read	O
during	O
the	O
transaction	O
for	O
diagnostic	O
purposes	O
.	O
</s>
<s>
STM	O
can	O
be	O
implemented	O
as	O
a	O
lock-free	O
algorithm	O
or	O
it	O
can	O
use	O
locking	B-Operating_System
.	O
</s>
<s>
There	O
are	O
two	O
types	O
of	O
locking	B-Operating_System
schemes	O
:	O
In	O
encounter-time	O
locking	B-Operating_System
(	O
Ennals	O
,	O
Saha	O
,	O
and	O
Harris	O
)	O
,	O
memory	O
writes	O
are	O
done	O
by	O
first	O
temporarily	O
acquiring	O
a	O
lock	O
for	O
a	O
given	O
location	O
,	O
writing	O
the	O
value	O
directly	O
,	O
and	O
logging	O
it	O
in	O
the	O
undo	O
log	O
.	O
</s>
<s>
Commit-time	O
locking	B-Operating_System
locks	O
memory	O
locations	O
only	O
during	O
the	O
commit	O
phase	O
.	O
</s>
<s>
A	O
commit-time	O
scheme	O
named	O
"	O
Transactional	O
Locking	B-Operating_System
II	O
"	O
implemented	O
by	O
Dice	O
,	O
Shalev	O
,	O
and	O
Shavit	O
uses	O
a	O
global	O
version	O
clock	O
.	O
</s>
<s>
An	O
increasingly	O
utilized	O
method	O
to	O
manage	O
transactional	O
conflicts	O
in	O
Transactional	B-Operating_System
memory	I-Operating_System
,	O
and	O
especially	O
in	O
STM	O
,	O
is	O
Commitment	B-Architecture
ordering	I-Architecture
(	O
also	O
called	O
Commit	B-Architecture
ordering	I-Architecture
;	O
CO	O
)	O
.	O
</s>
<s>
It	O
is	O
utilized	O
for	O
achieving	O
serializability	B-Operating_System
optimistically	O
(	O
i.e.	O
,	O
without	O
blocking	O
upon	O
conflict	O
,	O
and	O
only	O
locking	B-Operating_System
for	O
commit	O
)	O
by	O
"	O
commit	B-Architecture
order	I-Architecture
"	O
(	O
e.g.	O
,	O
Ramadan	O
et	O
al	O
.	O
</s>
<s>
Serializability	B-Operating_System
is	O
the	O
basis	O
for	O
the	O
correctness	O
of	O
(	O
concurrent	O
transactions	O
and	O
)	O
transactional	B-Operating_System
memory	I-Operating_System
.	O
</s>
<s>
Tens	O
of	O
STM	O
articles	O
on	O
"	O
commit	B-Architecture
order	I-Architecture
"	O
have	O
already	O
been	O
published	O
,	O
and	O
the	O
technique	O
is	O
encumbered	O
by	O
a	O
number	O
of	O
patents	O
.	O
</s>
<s>
With	O
CO	O
the	O
desired	O
serializability	B-Operating_System
property	O
is	O
achieved	O
by	O
committing	O
transactions	O
only	O
in	O
chronological	O
order	O
that	O
is	O
compatible	O
with	O
the	O
precedence	O
order	O
(	O
as	O
determined	O
by	O
chronological	O
orders	O
of	O
operations	O
in	O
conflicts	O
)	O
of	O
the	O
respective	O
transactions	O
.	O
</s>
<s>
The	O
patent	O
abstract	O
quoted	O
above	O
describes	O
a	O
general	O
implementation	O
of	O
the	O
algorithm	O
with	O
a	O
pre-determined	O
commit	B-Architecture
order	I-Architecture
(	O
this	O
falls	O
into	O
the	O
category	O
of	O
"	O
CO	O
generic	O
algorithm	O
with	O
real-time	O
constraints	O
"	O
)	O
.	O
</s>
<s>
One	O
problem	O
with	O
implementing	O
software	B-Operating_System
transactional	I-Operating_System
memory	I-Operating_System
with	O
optimistic	B-Operating_System
reading	O
is	O
that	O
it	O
is	O
possible	O
for	O
an	O
incomplete	O
transaction	O
to	O
read	O
inconsistent	O
state	O
(	O
that	O
is	O
,	O
to	O
read	O
a	O
mixture	O
of	O
old	O
and	O
new	O
values	O
written	O
by	O
another	O
transaction	O
)	O
.	O
</s>
<s>
One	O
way	O
to	O
deal	O
with	O
these	O
issues	O
is	O
to	O
detect	O
transactions	O
that	O
execute	O
illegal	O
operations	O
or	O
fail	O
to	O
terminate	O
and	O
abort	O
them	O
cleanly	O
;	O
another	O
approach	O
is	O
the	O
transactional	O
locking	B-Operating_System
scheme	O
.	O
</s>
