Skip to content

Instantly share code, notes, and snippets.

View adamw's full-sized avatar

Adam Warski adamw

View GitHub Profile
View x.scala
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:
View test.java
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)
View test.scala
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
View test.java
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;
View test.java
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(() -> {
View Rendezvous.java
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) {
View Rendezvous.java
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;
}
View accumulator.sc
//> 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 {
View update_signature.md
.libv1> builtins.merge
test1: Nat -> Nat
test1 n = n + n
View x.scala
package sttp.tapir.examples
import cats.effect.{ExitCode, IO, IOApp}
import org.http4s.HttpRoutes
import org.http4s.blaze.server.BlazeServerBuilder
import org.http4s.server.Router
import sttp.model.{Part, StatusCode}
import sttp.model.headers.WWWAuthenticateChallenge
import sttp.tapir._
import sttp.tapir.generic.auto._