This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Right now I am: cruising the boulevard with my Chevrolet Bel Air |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class Vehicle { | |
var make = "" | |
var model = "" | |
} | |
interface LandVehicle | |
fun <T> T.cruiseTheBoulevard(): String where T: Vehicle, T: LandVehicle { | |
return "cruising the boulevard with my $make $model" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Right now I am: cruising the boulevard with my Chevrolet Bel Air | |
Right now I am: cruising the boulevard with my SpaceX Starship |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class Vehicle { | |
var make = "" | |
var model = "" | |
} | |
interface LandVehicle | |
fun Vehicle.cruiseTheBoulevard(): String { | |
return "cruising the boulevard with my $make $model" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Vehicle.cruiseTheBoulevard(): String { | |
return "cruising the boulevard with my ${getMakeAndModel()}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface LandVehicle | |
fun <T> T.cruiseTheBoulevard(): String where T: Vehicle, T: LandVehicle { | |
return "cruising the boulevard with my ${getMakeAndModel()}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Vehicle.cruiseTheBoulevard(): String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Test Run | With Mutex | No Mutex | |
---|---|---|---|
1 | 10000 | 10000 | |
2 | 10000 | 9094 | |
3 | 10000 | 8895 | |
4 | 10000 | 10000 | |
5 | 10000 | 10000 | |
6 | 10000 | 9570 | |
7 | 10000 | 9137 | |
8 | 10000 | 9591 | |
9 | 10000 | 10000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.* | |
import kotlinx.coroutines.Dispatchers.Default | |
import kotlinx.coroutines.sync.Mutex | |
import kotlinx.coroutines.sync.withLock | |
private val mutex = Mutex() // our hero ;-) | |
private var counterWithMutex = 0 | |
private var counterNoMutex = 0 | |
suspend fun main( ) { |