Skip to content

Instantly share code, notes, and snippets.

View stepancheg's full-sized avatar

Stepan Koltsov stepancheg

View GitHub Profile
@stepancheg
stepancheg / xx.ll
Last active June 29, 2017 23:00
--emit=llvm-ir
; ModuleID = 'xx.cgu-0.rs'
source_filename = "xx.cgu-0.rs"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-darwin"
%str_slice = type { i8*, i64 }
%"alloc::vec::Vec<u8>" = type { %"alloc::raw_vec::RawVec<u8, alloc::heap::HeapAlloc>", [0 x i8], i64, [0 x i8] }
%"alloc::raw_vec::RawVec<u8, alloc::heap::HeapAlloc>" = type { %"core::ptr::Unique<u8>", [0 x i8], i64, [0 x i8], %"alloc::heap::HeapAlloc", [0 x i8] }
%"core::ptr::Unique<u8>" = type { %"core::nonzero::NonZero<*const u8>", [0 x i8], %"core::marker::PhantomData<u8>", [0 x i8] }
%"core::nonzero::NonZero<*const u8>" = type { i8*, [0 x i8] }
struct CyclicBarrierShared {
count: u32,
mutex: Mutex<(u32, bool)>,
condv: Condvar,
}
struct CyclicBarrier {
shared: Arc<CyclicBarrierShared>,
}
use std::boxed::Box;
use std::sync::atomic::AtomicPtr;
use std::sync::atomic::Ordering;
use std::ptr;
use std::mem;
/// Atomic holder of `Option<Box<T>>`.
///
/// `AtomicBoxOption` owns a pointer, thus it `drop` content on self `drop`.
@stepancheg
stepancheg / pthread_cond_timedwait_bug.c
Last active September 14, 2021 09:10
Bug in pthread_cond_timedwait in OSX with superlong timeout
#include <stdio.h>
#include <pthread.h>
int main() {
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t condvar = PTHREAD_COND_INITIALIZER;
int r = pthread_mutex_lock(&mutex);
if (r != 0) {
perror("pthread_mutex_lock");
return 1;
@stepancheg
stepancheg / mpsc.md
Last active June 9, 2017 06:37
Explanation why patch works

Lengthy explanation why patch works.

Sender part is simple: it (either pushes a message or sets "closed" flag) and then calls notify if any task is registered.

The interesting part is function

poll_queue_and_open

Function starts with optimistic pop:

use std::boxed::Box;
use std::sync::atomic::AtomicPtr;
use std::sync::atomic::Ordering;
use std::ptr;
use std::mem;
/// Max value for flag stored in `AtomicBoxOrFlag`
/// `3` is safe value, because pointers are at least 4-byte aligned.
/// Although in practice `malloc` never return small addresses,
package org.asynchttpclient.future;
import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
* @author Stepan Koltsov
// HTTP/2 request of response stream is a sequence of frames.
// Header frames can be interleaves with data frames.
enum HttpStreamPart {
Headers(Vec<Header>),
Body(Vec<u8>),
}
// To be implemented by user.
//
// Server may start sending response before
use std::io;
use futures::Future;
use futures::Poll;
use futures::Async;
use futures::stream::Stream;
use tokio_core;
use tokio_core::reactor;
User-Agent: *
Allow: /
Disallow: /cgi-bin
Disallow: /booking
Disallow: /cont
Disallow: /counters
Disallow: /dig
Disallow: /chat
Disallow: /chat2
Disallow: /css