.libv1> builtins.merge
test1: Nat -> Nat
test1 n = n + n
//> using dep com.softwaremill.sttp.tapir::tapir-netty-server-sync:1.10.7 | |
import ox.channels.{Actor, ActorRef, Channel, ChannelClosed, Default, DefaultResult, selectOrClosed} | |
import ox.{fork, releaseAfterScope, supervised} | |
import sttp.tapir.* | |
import sttp.tapir.CodecFormat.* | |
import sttp.tapir.server.netty.sync.{Id, NettySyncServer, OxStreams} | |
import java.util.UUID |
package brc | |
import monix.eval.Task | |
import monix.execution | |
import monix.reactive.Observable | |
import java.io.{BufferedReader, FileInputStream, InputStreamReader} | |
import java.text.DecimalFormat | |
object UsingMonix: |
import java.lang.invoke.MethodHandles; | |
import java.lang.invoke.VarHandle; | |
import java.util.concurrent.Exchanger; | |
import java.util.concurrent.atomic.AtomicReference; | |
import java.util.concurrent.locks.LockSupport; | |
// with changes inspired by Exchanger | |
public class Rendezvous2 { | |
private volatile Thread waiting; | |
private volatile int data = -1; // together with `consumed`, used to transmit data if t1 wins the race (and waits for t2) |
import cats.effect.{Deferred, IO, Ref} | |
import cats.effect.std.Queue | |
import cats.effect.unsafe.implicits.global | |
import java.util.concurrent.Executors | |
import scala.concurrent.ExecutionContext | |
// max times rendezvous using cats-effect's synchronous queue | |
def rendezvousUsingCatsEffect(): Unit = | |
val max = 10_000_000 |
import java.util.concurrent.atomic.AtomicReference; | |
import java.util.concurrent.locks.LockSupport; | |
public class Rendezvous { | |
private final int spinIterations; | |
private final int yieldIterations; | |
private final AtomicReference<ThreadAndCell> waiting = new AtomicReference<>(); | |
public Rendezvous(int spinIterations, int yieldIterations) { | |
this.spinIterations = spinIterations; |
import java.util.concurrent.Exchanger; | |
import java.util.concurrent.SynchronousQueue; | |
public class RendezvousUsingExchanger { | |
public static void test() throws Exception { | |
long startTime = System.currentTimeMillis(); | |
final int max = 10_000_000; | |
Exchanger<Integer> data = new Exchanger<>(); | |
Thread t1 = Thread.ofVirtual().start(() -> { |
import java.util.concurrent.atomic.AtomicReference; | |
import java.util.concurrent.locks.LockSupport; | |
// -Djdk.virtualThreadScheduler.parallelism=1 -Djdk.virtualThreadScheduler.maxPoolSize=1 -Djdk.virtualThreadScheduler.minRunnable=1 | |
public class Rendezvous { | |
private final int spinIterations; | |
private final int yieldIterations; | |
private final AtomicReference<ThreadAndCell> waiting = new AtomicReference<>(); | |
public Rendezvous(int spinIterations, int yieldIterations) { |
import java.util.concurrent.atomic.AtomicReference; | |
import java.util.concurrent.locks.LockSupport; | |
public class Rendezvous { | |
private final boolean yieldOnFirstIteration; | |
private final AtomicReference<ThreadAndCell> waiting = new AtomicReference<>(); | |
public Rendezvous(boolean yieldOnFirstIteration) { | |
this.yieldOnFirstIteration = yieldOnFirstIteration; | |
} |
//> using dep com.softwaremill.ox::core:0.0.7 | |
import ox.* | |
import ox.channels.* | |
import scala.annotation.tailrec | |
scoped { | |
// fast producer | |
val c = Channel[Int]() | |
fork { |
.libv1> builtins.merge
test1: Nat -> Nat
test1 n = n + n