gpt4 book ai didi

multithreading - glib线程安全吗?

转载 作者:行者123 更新时间:2023-12-03 13:16:11 26 4
gpt4 key购买 nike

我在glib文档中找不到有关线程安全的任何信息。我想这意味着我可能应该假设它不是线程安全的,但是我不确定应该锁定哪些共享资源。

有人使用glib有线程安全方面的经验吗?我可以使用什么准则来确保我的glib代码是线程安全的?

谢谢!

最佳答案

实际上,glib引用手册中包含有关线程安全性的全部信息:

After calling g_thread_init(), GLib is completely thread safe (all global data is automatically locked), but individual data structure instances are not automatically locked for performance reasons. So, for example you must coordinate accesses to the same GHashTable from multiple threads. The two notable exceptions from this rule are GMainLoop and GAsyncQueue, which are threadsafe and need no further application-level locking to be accessed from multiple threads.



您可能需要查看引用手册的 threads section

关于multithreading - glib线程安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10094723/

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