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
//> 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 |
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
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: |
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.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) |
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 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 |
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.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; |
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.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(() -> { |
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.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) { |
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.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; | |
} |
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
// TestMacro.scala | |
import scala.quoted.* | |
object TestMacro { | |
inline def name[E](e: E): String = ${ nameImpl[E]('e) } | |
def nameImpl[E: Type](e: Expr[E])(using Quotes): Expr[String] = { | |
import quotes.reflect.* |
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
//> 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 { |
NewerOlder