synchronous streams implementation in C