This file contains hidden or 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
const std = @import("std"); | |
const system = switch (std.builtin.os.tag) { | |
.linux => std.os.linux, | |
else => std.os.system, | |
}; | |
const ThreadPool = @This(); | |
max_threads: u16, | |
counter: u32 = 0, |
This file contains hidden or 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
pub fn ParkingLot(comptime Config: type) type { | |
return struct { | |
pub const Lock: type = Config.Lock; | |
pub const Event: type = Config.Event; | |
pub const nanotime: fn() u64 = switch (@hasDecl(Config, "nanotime")) { | |
true => Config.nanotime, |
This file contains hidden or 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
const std = @import("std"); | |
pub fn main() !void { | |
try (try ThreadPool.run(.{}, realMain, .{})); | |
} | |
/////// Using the Thread Pool ////// | |
fn realMain() !void { | |
const WaitGroup = struct { |
This file contains hidden or 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
const std = @import("std"); | |
// usage: | |
fn asyncMain() !void | |
{ | |
// Start two interleaving tasks | |
var task_a = async waitUntilAndPrint(1000, 1200, "task a"); | |
var task_b = async waitUntilAndPrint(500, 1300, "task b"); | |
await task_a; |
This file contains hidden or 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
const std = @import("std"); | |
const allocator = std.heap.page_allocator; | |
pub fn main() !void { | |
const n = 10; | |
const ret = try (try Task.run(fib, .{n})); | |
std.debug.warn("fib({}) = {}\n", .{n, ret}); | |
} | |
fn fib(n: usize) std.mem.Allocator.Error!usize { |
This file contains hidden or 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
// Bit-vector + rand shuffle order scheduler | |
const std = @import("std"); | |
const Allocator = std.mem.Allocator; | |
const workload_size = 1 << 20; | |
const n_workloads = 4; | |
const repetition = 4; | |
const use_async = true; | |
const use_manual_prefetch = true; |
This file contains hidden or 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
const std = @import("std"); | |
const net = @import("./zig-network/network.zig"); | |
const PROTOCOL = net.Protocol.tcp; | |
pub fn main() !void { | |
var buf: [1 * 1024 * 1024]u8 = undefined; | |
var fba = std.heap.FixedBufferAllocator.init(&buf); | |
try net.init(); |
This file contains hidden or 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
[sync_mutex_throughput] std::sync::Mutex threads=1 work_per_lock=1 | |
time: [22.027 ns 22.117 ns 22.213 ns] | |
Found 12 outliers among 100 measurements (12.00%) | |
6 (6.00%) high mild | |
6 (6.00%) high severe | |
[sync_mutex_throughput] parking_lot::Mutex threads=1 work_per_lock=1 | |
time: [19.025 ns 19.935 ns 20.868 ns] | |
Found 1 outliers among 100 measurements (1.00%) | |
1 (1.00%) high mild |
This file contains hidden or 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
const std = @import("std"); | |
pub const Mutex = struct { | |
state: usize, | |
const MUTEX_LOCK: usize = 0b01; | |
const QUEUE_LOCK: usize = 0b10; | |
const QUEUE_MASK: usize = ~@as(usize, @alignOf(Node) - 1); | |
const Node = struct { |
This file contains hidden or 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.Map; | |
import java.util.List; | |
import java.util.HashMap; | |
import java.util.ArrayList; | |
import java.util.LinkedHashMap; | |
import java.net.URL; | |
import java.net.URLEncoder; |