Discussion:
[e-lang] Race in ETimeFormat [PATCH]
Thomas Leonard
2011-07-28 09:15:58 UTC
Permalink
If two vats use ETimeFormat at once, it may fail. Test case:


def seedVat := <elang:interp.seedVatAuthor>(<unsafe>)
seedVat(`def timeFormat :=
<import:org.erights.e.develop.format.makeETimeFormat>
def random := <unsafe:java.util.makeRandom>()
while (true) { timeFormat.formatTime(random.nextInt()) }`)

def timeFormat := <import:org.erights.e.develop.format.makeETimeFormat>
while (true) {timeFormat.formatTime(0) }


Sample output:

$ rune time.e
# problem: <ArrayIndexOutOfBoundsException: 13>
#
# - static ETimeFormat#formatTime(long)
# . <makeETimeFormat>.formatTime(0)
# @ formatTime/1: </opt/src/e/src/time.e#:span::7:25::7:34>
# - __main$_#run/0
# . <_>()
# - Loop#run(LoopBody)
# . <__loop>(<_>)
# @ run/1
# - EExpr#evalToPair(Scope)
# . e`escape __break {\n __lo... }\n }\n
})\n}`.evalToPair(<a Scope>)
# @ evalToPair/1:
<jar:file:/home/tal/.cache/0install.net/implementations/sha1new%3d489654cfd0f86baaf3223c77418b2e3427255731/e.jar!/org/erights/e/elang/cmd/cmdMakerMaker.emaker#:span::128:57::128:66>


Patch:

https://gitorious.org/~tal-itinnov/repo-roscidus/it-innovation/commit/057f7265156b930493ae217277a4e93e442a3400
--
Dr Thomas Leonard
IT Innovation Centre
Gamma House, Enterprise Road,
Southampton SO16 7NS, UK


tel: +44 23 8059 8866

mailto:***@it-innovation.soton.ac.uk
http://www.it-innovation.soton.ac.uk/
Mark S. Miller
2011-07-28 13:53:31 UTC
Permalink
Hi Thomas,

I see at <
http://download.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html
Date formats are not synchronized. It is recommended to create separate
format instances for each thread. If multiple threads access a format
concurrently, it must be synchronized externally.

which surprises me. But given that, your fix looks good and necessary.
Thanks!


On Thu, Jul 28, 2011 at 2:15 AM, Thomas Leonard <
Post by Thomas Leonard
def seedVat := <elang:interp.seedVatAuthor>(<unsafe>)
seedVat(`def timeFormat :=
<import:org.erights.e.develop.format.makeETimeFormat>
def random := <unsafe:java.util.makeRandom>()
while (true) { timeFormat.formatTime(random.nextInt()) }`)
def timeFormat := <import:org.erights.e.develop.format.makeETimeFormat>
while (true) {timeFormat.formatTime(0) }
$ rune time.e
# problem: <ArrayIndexOutOfBoundsException: 13>
#
# - static ETimeFormat#formatTime(long)
# . <makeETimeFormat>.formatTime(0)
# - __main$_#run/0
# . <_>()
# - Loop#run(LoopBody)
# . <__loop>(<_>)
# - EExpr#evalToPair(Scope)
# . e`escape __break {\n __lo... }\n }\n
})\n}`.evalToPair(<a Scope>)
<jar:file:/home/tal/.cache/
0install.net/implementations/sha1new%3d489654cfd0f86baaf3223c77418b2e3427255731/e.jar!/org/erights/e/elang/cmd/cmdMakerMaker.emaker#:span::128:57::128:66
https://gitorious.org/~tal-itinnov/repo-roscidus/it-innovation/commit/057f7265156b930493ae217277a4e93e442a3400
--
Dr Thomas Leonard
IT Innovation Centre
Gamma House, Enterprise Road,
Southampton SO16 7NS, UK
tel: +44 23 8059 8866
http://www.it-innovation.soton.ac.uk/
_______________________________________________
e-lang mailing list
http://www.eros-os.org/mailman/listinfo/e-lang
--
Cheers,
--MarkM
Kevin Reid
2011-07-28 14:37:22 UTC
Permalink
Post by Thomas Leonard
https://gitorious.org/~tal-itinnov/repo-roscidus/it-innovation/commit/057f7265156b930493ae217277a4e93e442a3400
Looks good; please commit.
--
Kevin Reid <http://switchb.org/kpreid/>
Loading...