Skip to content

Instantly share code, notes, and snippets.

View stepancheg's full-sized avatar

Stepan Koltsov stepancheg

View GitHub Profile
public final boolean getAndSet(boolean newValue) {
boolean prev;
do {
prev = get();
} while (!compareAndSet(prev, newValue));
return prev;
}
public final int getAndSet(int newValue) {
return unsafe.getAndSetInt(this, valueOffset, newValue);
}
User-Agent: *
Allow: /
Disallow: /cgi-bin
Disallow: /booking
Disallow: /cont
Disallow: /counters
Disallow: /dig
Disallow: /chat
Disallow: /chat2
Disallow: /css
use std::io;
use futures::Future;
use futures::Poll;
use futures::Async;
use futures::stream::Stream;
use tokio_core;
use tokio_core::reactor;
// 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
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
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,
@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:

@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;
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`.