Professional Documents
Culture Documents
4 Immutability
4 Immutability
4 Immutability
2xCourseware|edX
Reading 4: Parser
Immutable objects are usually also threadsafe. We say usually here because our current
Generators
Reading Exercise due Apr 24, denition of immutability is too loose for concurrent programming. We've said that a type is
2017 14:00 CDT immutable if an object of the type always represents the same abstract value for its entire
Reading 5: Concurrency lifetime. But that actually allows the type the freedom to mutate its rep, as long as those
Reading Exercise due Apr 24, mutations are invisible to clients. We saw an example of this notion, called benevolent or
2017 14:00 CDT
benecent mutation, when we looked at an immutable list that cached its length in a mutable
Reading 6: Thread Safety eld the rst time the length was requested by a client. Caching is a typical kind of benecent
Reading Exercise due Apr 24,
2017 14:00 CDT mutation.
no mutation whatsoever of mutable objects in the rep not even benecent mutation
Week 1
If you follow these rules, then you can be condent that your immutable type will also be
threadsafe.
Week 2
Week 5
Discussion Show Discussion
Topic: Reading 6 / Strategy 2: Immutability
Week 6
https://courses.edx.org/courses/coursev1:MITx+6.005.2x+1T2017/courseware/Readings/06ThreadSafety/ 1/2
3/31/2017 Strategy2:Immutability|Reading6:ThreadSafety|6.005.2xCourseware|edX
2012-2017 edX Inc. All rights reserved except where noted. EdX, Open edX and the edX and Open EdX logos are registered trademarks or
trademarks of edX Inc.
https://courses.edx.org/courses/coursev1:MITx+6.005.2x+1T2017/courseware/Readings/06ThreadSafety/ 2/2