首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >libgit2中的全局操作需要同步吗?

libgit2中的全局操作需要同步吗?
EN

Stack Overflow用户
提问于 2020-05-14 09:14:29
回答 1查看 68关注 0票数 0

我一直从cache_store那里得到赞的报告。

文档中说,我需要防止在每个对象之上并发访问,但根据TSAN的说法,我将其解释为对每个git_repository对象的并发访问。所有派生对象都需要使用相同的锁(例如git_commitgit_tree等)。对吗?

TSAN产出:

代码语言:javascript
复制
WARNING: ThreadSanitizer: data race (pid=28177)
  Atomic write of size 4 at 0x55bc2dc780ec by thread T14 (mutexes: write M889877933370572712):
    #0 __tsan_atomic32_fetch_add <null> (libtsan.so.0+0x6c101)
    #1 git_atomic_add external/libgit2/src/thread-utils.h:82 (analyze_remote_git+0x46e240)
    #2 cache_store external/libgit2/src/cache.c:200 (analyze_remote_git+0x46ed4c)
    #3 git_cache_store_raw external/libgit2/src/cache.c:231 (analyze_remote_git+0x46eec0)
    #4 odb_read_1 external/libgit2/src/odb.c:1095 (analyze_remote_git+0x413b73)
    #5 git_odb_read external/libgit2/src/odb.c:1116 (analyze_remote_git+0x413cdf)
    #6 git_object_lookup_prefix external/libgit2/src/object.c:221 (analyze_remote_git+0x4056ab)
    #7 git_object_lookup external/libgit2/src/object.c:252 (analyze_remote_git+0x4057d1)
    #8 git_commit_lookup external/libgit2/src/object_api.c:23 (analyze_remote_git+0x40f980)
    #9 create_branch external/libgit2/src/clone.c:41 (analyze_remote_git+0x37c582)
    #10 create_tracking_branch external/libgit2/src/clone.c:102 (analyze_remote_git+0x37c880)
    #11 update_head_to_new_branch external/libgit2/src/clone.c:124 (analyze_remote_git+0x37c94e)
    #12 update_head_to_remote external/libgit2/src/clone.c:189 (analyze_remote_git+0x37cc5c)
    #13 checkout_branch external/libgit2/src/clone.c:315 (analyze_remote_git+0x37d1b1)
    #14 clone_into external/libgit2/src/clone.c:348 (analyze_remote_git+0x37d460)
    #15 git__clone external/libgit2/src/clone.c:432 (analyze_remote_git+0x37da83)
    #16 git_clone external/libgit2/src/clone.c:463 (analyze_remote_git+0x37dbfc)
... ADDITIONAL STACK REMOVED ...

  Previous read of size 4 at 0x55bc2dc780ec by thread T13 (mutexes: write M1852):
    #0 cache_store external/libgit2/src/cache.c:192 (analyze_remote_git+0x46ec31)
    #1 git_cache_store_parsed external/libgit2/src/cache.c:237 (analyze_remote_git+0x46ef20)
    #2 git_object__from_odb_object external/libgit2/src/object.c:148 (analyze_remote_git+0x405314)
    #3 git_object_lookup_prefix external/libgit2/src/object.c:244 (analyze_remote_git+0x405747)
    #4 git_object_lookup external/libgit2/src/object.c:252 (analyze_remote_git+0x4057d1)
    #5 git_tree_lookup external/libgit2/src/object_api.c:56 (analyze_remote_git+0x40fb0f)
    #6 tree_walk external/libgit2/src/tree.c:978 (analyze_remote_git+0x3a22f5)
    #7 tree_walk external/libgit2/src/tree.c:989 (analyze_remote_git+0x3a237e)
    #8 tree_walk external/libgit2/src/tree.c:989 (analyze_remote_git+0x3a237e)
    #9 git_tree_walk external/libgit2/src/tree.c:1025 (analyze_remote_git+0x3a2545)
... ADDITIONAL STACK REMOVED ...

  Location is global 'git_cache__current_storage' of size 4 at 0x55bc2dc780ec (analyze_remote_git+0x0000011d60ec)

  Mutex M889877933370572712 is already destroyed.

  Mutex M1852 (0x7b4400019f28) created at:
    #0 pthread_rwlock_init <null> (libtsan.so.0+0x2ef82)
    #1 git_cache_init external/libgit2/src/cache.c:72 (analyze_remote_git+0x46e61f)
    #2 repository_alloc external/libgit2/src/repository.c:245 (analyze_remote_git+0x416764)
    #3 git_repository_open_ext external/libgit2/src/repository.c:829 (analyze_remote_git+0x418cfe)
    #4 git_repository_open external/libgit2/src/repository.c:887 (analyze_remote_git+0x419127)
    #5 git_repository_init_ext external/libgit2/src/repository.c:2112 (analyze_remote_git+0x41ced5)
    #6 git_repository_init external/libgit2/src/repository.c:2056 (analyze_remote_git+0x41c97b)
    #7 default_repository_create external/libgit2/src/clone.c:234 (analyze_remote_git+0x37ce3e)
    #8 git__clone external/libgit2/src/clone.c:420 (analyze_remote_git+0x37d8cb)
    #9 git_clone external/libgit2/src/clone.c:463 (analyze_remote_git+0x37dbfc)
... ADDITIONAL STACK REMOVED ...
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-24 19:34:25

文档说,我需要在每个对象之上防止并发访问,但是根据TSAN的说法,我将其解释为对每个git_repository对象的并发访问。所有派生对象都需要使用相同的锁(例如git_commit、git_tree等)。对吗?

是。git_repository及其派生的所有对象只能由单个线程使用。

git_repository是轻量级的,它的目的是安全地与其他git_repository(以及其他进程中的其他git客户机,包括命令行中git的使用)进行交互。因此,您应该可以跨多个线程创建多个git_repository对象。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61793588

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档