Farama-Foundation / Arcade-Learning-Environment

The Arcade Learning Environment (ALE) -- a platform for AI research.
https://ale.farama.org/
GNU General Public License v2.0
2.18k stars 424 forks source link

Odd assertion failure when trying to run multiple ALEs from different threads #86

Closed UserAB1236872 closed 9 years ago

UserAB1236872 commented 9 years ago

I'm using the ALE C lib, and I'm trying to run multiple separate games from different threads. Up until about 3 threads this is stable and seems to work fine, but at thread 4 I start getting this error:

File: [...]/Arcade-Learning-Environment/src/emucore/TIA.cxx, Line 1147

Expression: (s1 % 4 == 0) && (s2 % 8 == 0)
An unknown error occurred

Each thread locally invokes ALE_new and loads its own ROM, so they're not sharing instances. This problem does not occur when running multiple programs that individually link with the ALE C shared library with &.

This should probably be reproduced by someone else first to see if this is a local anomaly.

mgbellemare commented 9 years ago

Hi @Jragonmiris -- as you probably figured out, as of now ALE isn't completely thread-safe (though the dev branch should be close to). In particular, new ALEs are created from static data, so ALEs within one process should not be created simultaneously.

ppwwyyxx commented 8 years ago

Also see the same problem with multithreading, using the version at 8a58802c12. The log shows that two ALE instance are initialized at the same time (in milliseconds) right before the assertion.

2016-06-11 19:54:04.193 A.L.E: Arcade Learning Environment (version 0.5.1)
2016-06-11 19:54:04.193 [Powered by Stella]
2016-06-11 19:54:04.193 Use -help for help screen.
2016-06-11 19:54:04.193 Warning: couldn't load settings file: ./ale.cfg
2016-06-11 19:54:04.193 A.L.E: Arcade Learning Environment (version 0.5.1)
2016-06-11 19:54:04.193 [Powered by Stella]
2016-06-11 19:54:04.193 Use -help for help screen.
2016-06-11 19:54:04.193 Warning: couldn't load settings file: ./ale.cfg
2016-06-11 19:54:04.219 python2: /home/yuxinwu/install/Arcade-Learning-Environment/src/emucore/TIA.cxx:1147: void TIA::computePlayerPositionResetWhenTable(): Assertion `(s1 % 4 == 0) && (s2 % 8 == 0)' failed.

It seems to work well before when no two instances are initialized at the same time. I'll just add some delay to see if it happens again.