gpt4 book ai didi

multithreading - Chdir 和Setuid 以及Setgid 线程安全吗?

转载 作者:IT王子 更新时间:2023-10-29 01:51:35 26 4
gpt4 key购买 nike

os. Chdiros.Setuidos.Setgid 在 Go 中线程安全吗?

换句话说,如果我在两个并行运行的不同 goroutine 中执行 os.Chdir(或其他两个函数),它会改变工作 goroutine 的目录还是整个过程(这会导致问题)?

我在文档中找不到任何信息。

最佳答案

在引擎盖下,os.Chdir 只是 calls chdir() 系统调用:

   211  func Chdir(dir string) error {
212 if e := syscall.Chdir(dir); e != nil {
213 return &PathError{"chdir", dir, e}
214 }
215 return nil
216 }

所以它影响了整个过程。 os.Setuidos.Setgid 也是如此。

同时从多个 goroutine 调用它们可能是安全的,因为执行系统调用会暂停调度程序;但要注意竞争条件。

关于multithreading - Chdir 和Setuid 以及Setgid 线程安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23180000/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com