https://kotlinlang.org logo
#coroutines
Title
# coroutines
u

uli

12/06/2018, 5:21 PM
@zokipirlo see the above thread, this code is broken no matter if contains is thread safe or not. think about this scenario:
Copy code
launch(ioContext) {
	if (!mutableList.contains(something)) {
		modifyActor.send(Add(something))
	}
}
launch(ioContext) {
// Actor has not yet processed the 'Add' message, because it was busy processing other requests
	if (mutableList.contains(something)) {
		//We will not get here
		modifyActor.send(Remove(something))
	}
}
z

zokipirlo

12/07/2018, 7:18 AM
Yes, that's true. Remove would be lost. Will change implementation to two lists, where I will just add things (added and remove things). In worst case scenario it would send message to actor multiple times, but will be processed only once.
Thanks!
3 Views