ticket lock implementation in stream.c