End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
IO::Buffer#locked?
locked? → true or false
io_buffer.c
View on GitHub ↗
static VALUE
rb_io_buffer_locked_p(VALUE self)
{
struct rb_io_buffer *data = NULL;
TypedData_Get_Struct(self, struct rb_io_buffer, &rb_io_buffer_type, data);
return RBOOL(data->flags & RB_IO_BUFFER_LOCKED);
}
If the buffer is locked, meaning it is inside locked block execution. Locked buffer can’t be resized or freed, and another lock can’t be acquired on it.
Locking is not thread safe, but is a semantic used to ensure buffers don’t move while being used by a system call.
Example
buffer.locked do buffer.write(io) # theoretical system call interface end