Introduction to concurrency

Correct concurrent code is one that allows for a certain variability in the order of its execution while still being deterministic on the result. For this to be possible, different parts of the code need to have some level of independence, and some degree of orchestration may also be required. The best way to understand concurrency is by comparing sequential code with concurrent code. Let's start by looking at some non-concurrent code:

fun getProfile(id: Int) : Profile {    val basicUserInfo = getUserInfo(id)    val contactInfo = getContactInfo(id)    return createProfile(basicUserInfo, contactInfo)}

If I ask you what is going to be obtained first, the user information or the contact information – assuming no exceptions ...

Get Learning Concurrency in Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.