doufei1852 2014-04-20 08:23
浏览 126
已采纳

Chdir和Setuid和Setgid线程安全吗?

Are os. Chdir, os.Setuid and os.Setgid thread-safe in Go?

In otherwords, if I do a os.Chdir (or the other two functions) in two different goroutines running in parallel, is it going change directory for the working goroutine or the whole process (which can cause problems)?

I couldn't find any information in the documentation.

  • 写回答

1条回答 默认 最新

  • doupa9062 2014-04-20 08:35
    关注

    Under the hood, os.Chdir just calls the chdir() system call:

       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  }
    

    So it affects the entire process. The same is true for os.Setuid and os.Setgid.

    It is probably safe to call these from multiple goroutines at the same time, because executing a system call halts the scheduler; but beware of race conditions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效