简体   繁体   English

开罗图形图书馆是否可以重入?

[英]Is the Cairo Graphics Library Reentrant?

If I use two different cairo_t (and related cairo_surface_t etc) objects in two different threads, can I be guaranteed that there will be no race conditions due to shared global state? 如果我在两个不同的线程中使用两个不同的cairo_t (和相关的cairo_surface_t等)对象,我可以保证由于共享的全局状态不会有竞争条件吗?

Can I also formally pass a cairo_t object from one thread to another without any unexpected behaviour (possibly arising from thread local storage)? 我是否还可以正式将cairo_t对象从一个线程传递到另一个线程而没有任何意外行为(可能来自线程本地存储)?

This bug-tracking discussion should answer your questions : https://bugs.freedesktop.org/show_bug.cgi?id=74355 此错误跟踪讨论应该回答您的问题: https//bugs.freedesktop.org/show_bug.cgi?id = 74355

1. Cairo should be re-entrant 1.开罗应该是可重入的

Uli Schlachter 2014-02-03 18:25:06 UTC Uli Schlachter 2014-02-03 18:25:06 UTC

(In reply to comment #0) (回复评论#0)

  1. share a single cairo_surface_t between the threads, and have each thread draw using its own cairo_t. 在线程之间共享一个cairo_surface_t,并使用自己的cairo_t绘制每个线程。 This crashes, but maybe I'm hoping for too much (although an image surface is essentially just a big array of bytes that should be writable from multiple threads). 这会崩溃,但也许我希望太多(尽管图像表面基本上只是一个应该可以从多个线程写入的大字节数组)。

Sure, just an array. 当然,只是一个阵列。 And this works as long as you expect anything like useful results. 只要你期望有用的结果,这就有效。 Cairo is supposed to be thread-safe as long as the threads don't share any state (well, this is an oversimplification, but your first approach isn't supposed to work). 只要线程不共享任何状态,Cairo应该是线程安全的(好吧,这是过于简单化,但是你的第一种方法不应该起作用)。

2. Thread local storage can crash Pixman 线程本地存储可能会使Pixman崩溃

Søren Sandmann Pedersen 2014-02-17 16:49:02 UTC SørenSandmannPedersen 2014-02-17 16:49:02 UTC

It is possible that pixman's support for TLS on Windows is simply buggy; pixman对Windows上的TLS的支持可能只是错误的; it may be that not a lot of people have been using pixman in a multithreaded way on Windows (or have worked around the problem in some way). 可能不是很多人在Windows上以多线程方式使用pixman(或者以某种方式解决了这个问题)。 We will need some kind of way to reproduce the issue to know. 我们需要某种方式来重现问题才能知道。

In pixman 0.32.0 and later there is a test program called 'thread-test' that may reproduce this issue if you can get it running on Windows. 在pixman 0.32.0及更高版本中,有一个名为“thread-test”的测试程序可能会重现此问题,如果你可以在Windows上运行它。

As a policy, you should always consider third parties libraries not-tread safe, until proven otherwise. 作为一项政策,您应该始终认为第三方图书馆不是安全的,除非另有证明。

Since your title asks for reentrancy: There aren't many callbacks in cairo, but as long as you don't cause any recursive callbacks, you should be fine. 由于你的标题要求重入:cairo中没有很多回调,但只要你不引起任何递归回调,你应该没问题。

Cairo definitely isn't signal-safe and I can't really imagine it being so. 开罗肯定不是信号安全的,我无法想象它是如此。

And for your actual question about threads: There isn't that much global state in cairo and most of that is protected via apropriate mutexes. 关于线程的实际问题:在开罗中没有那么多的全局状态,其中大多数都是通过适当的互斥体来保护的。 There were/are some bugs with font locking. 有一些字体锁定错误。 If you stumble upon thread safety problems and can write a not-too-huge, self-contained program that reproduces the problem, the problem should be quickly fixed. 如果您遇到线程安全问题,并且可以编写一个不太大的,自包含的程序来重现问题,那么应该快速解决问题。 So any thread-safety issues are considered bugs. 因此任何线程安全问题都被视为错误。

And yes, this does not apply to sharing state between threads. 是的,这不适用于线程之间的共享状态。 Only implicitely used global state is protected. 只有隐含使用的全局状态才受到保护。 You cannot use any object that cairo hands to you in multiple threads at the same time. 你不能同时在多个线程中使用任何cairo交给你的对象。 But you can freely move an object between threads. 但是你可以在线程之间自由移动对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM