font-kit icon indicating copy to clipboard operation
font-kit copied to clipboard

Use static-assertions to check that fonts are indeed Send and Sync

Open nox opened this issue 6 years ago • 3 comments

See https://github.com/servo/core-foundation-rs/pull/347.

nox avatar Nov 05 '19 11:11 nox

I don't think FreeType is thread-safe in the same way though. (It's thread-safe in that the library can be used from multiple threads, but I don't think FT_Face methods take locks.) So if we're going to make fonts Sync we need to audit the methods to make sure non-thread-safe functions take &mut self.

I don't know about DirectWrite.

pcwalton avatar Jan 10 '20 06:01 pcwalton

There seems be a thread safe implementation for DirectWrite:

https://github.com/Connicpu/directwrite-rs/blob/64706009b30f4601f1c4b4b6f38653856ba10cdc/src/font/mod.rs#L26

Currently, we are using:

https://github.com/vvuk/dwrote-rs/blob/a75100ca9884880692d2523128a4eb5f279ec9b9/src/font.rs#L15

kaiwk avatar Oct 14 '20 02:10 kaiwk

The cairo docs specifically say that

You must be careful when using this function in a library or in a threaded application, because freetype's design makes it unsafe to call freetype functions simultaneously from multiple threads, (even if using distinct FT_Face objects).

So freetype is not threadsafe and you need to do your own locking (and know exactly what you have to lock: you might need a global freetype lock, I can't tell from that quote).

richard-uk1 avatar Oct 24 '20 19:10 richard-uk1