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 thread1() { | |
val results = arrayOfNulls<Any?>(2) { NO_RESULT } | |
val suspended = Array(2) { false } | |
val ch = Channel<Int>() | |
// send(5) | |
// receive() | |
val startSendBlock: suspend () -> Unit = { ch.send(5) } |
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
== Basic synchronization primitives == | |
(all of them should support cancellation) | |
Mutex: | |
isLocked: Boolean | |
tryLock(owner = null): Boolean | |
suspend lock(owner = null) | |
unlock(owner = null) | |
holdsLock(owner): Boolean |
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
public static void main(String[] args) { | |
// see https://github.com/Devexperts/lin-check | |
LinChecker.check(new LinearizabilityTest()); | |
} | |
@CTest(iterations = 1000, actorsPerThread = {"3:5", "3:5"}) | |
public static class LinearizabilityTest { | |
private Queue<Integer> q; | |
@Reset |
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 os | |
import math | |
def printAsBigHeader(s): | |
print '=' * len(s) | |
print s | |
print '=' * len(s) | |
return |
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
public class CopyUtils { | |
public static <T> T deepCopy(T origObj) { | |
Cloner cloner = new Cloner(); | |
try { | |
return cloner.clone(origObj); | |
} catch (InstantiationException e) { | |
throw new IllegalStateException(e); | |
} | |
} |
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 java.io.*; | |
import java.util.*; | |
public class Main { | |
public static void main(String[] args) { | |
InputStream inputStream = System.in; | |
OutputStream outputStream = System.out; | |
InputReader in = new InputReader(inputStream); | |
PrintWriter out = new PrintWriter(outputStream); | |