Home >Backend Development >Golang >Is bytes.Buffer thread-safe in Go?

Is bytes.Buffer thread-safe in Go?

Susan Sarandon
Susan SarandonOriginal
2024-11-12 16:43:021051browse

Is bytes.Buffer thread-safe in Go?

Go bytes.Buffer Thread Safety

In the Go programming language, the bytes.Buffer type implements a dynamically growing buffer of bytes. The documentation for bytes.Buffer does not explicitly mention thread safety. Is it thread-safe?

Answer

bytes.Buffer is not thread-safe.

The Go documentation adheres to the principle that if thread safety is not explicitly stated, it is not safe for concurrent access. Therefore, bytes.Buffer cannot be safely accessed by multiple goroutines simultaneously.

The above is the detailed content of Is bytes.Buffer thread-safe in Go?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn