最近在使用sdl做视频显示,因为需要显示文字,所以就找了sdl的拓展库,sdl_ttf来做文字显示。

这里说明一下:sdl_ttf不支持多线程,官方上面有说明,它不是多线程安全的。

所以当我最初使用sdl_ttf来做多线程显示文字的时候,就会出现崩溃的问题。

崩溃的地方老是出现在:FT_Load_Glyph这个函数。

然后我就发现,原来sdl_ttf不支持多线程,而sdl_ttf下的freetype它其实也是非多线程安全的,也只单线程使用。

同时在查找的过程中,我找到了几个很有用的帖子,这里贴出来给大家:

https://bugs.launchpad.net/ubuntu/+source/freetype/+bug/1199571

其中有人在多线程中使用freetype出现崩溃,然后把其作为Bug反馈给了freetype开发团队,上面就是Bug的反馈原内容。

然后还有这个:https://github.com/behdad/ftthread

这里是一个多线程测试freetype的tools,它是基于linux环境的。

我把帖子的内容贴出来:

ftthread
======== This is a test tool to use FreeType2 in a multi-threaded environment. FreeType2 is not thread-safe, and the original author(s) of FreeType
suggest that one FT_Library per thread should be used. Unfortunately
this is too inflexible to be really useful. However, there are ways to use it safely in a multi-threaded environment
with simple modifications to FreeType. I have now produced a complete
patchset to that effect and tested it using this utility. The patchset
is available here: https://github.com/behdad/freetype/commits/ftthread and I hope it to be integrated into upstream FreeType very soon. In
the mean time, here's the new threadsafety model, which needs to be
integrated into FreeType documentation. Note that cairo graphics
library already uses FreeType in this way and as such the entire GNOME
desktop has been relying on this model, to huge disappointment as seen
in the following bug reports, each of which have many duplicates: https://bugzilla.redhat.com/show_bug.cgi?id=678397
https://bugzilla.redhat.com/show_bug.cgi?id=1004315
https://bugzilla.redhat.com/show_bug.cgi?id=1164941
https://bugzilla.redhat.com/show_bug.cgi?id=1165471
https://bugs.freedesktop.org/show_bug.cgi?id=69034 Threadsafety model
================== - A FT_Face object can only be safely used from one thread at a time. - A FT_Library object can be used without modification from multiple
threads at the same time. - FT_Face creation / destruction with the same FT_Library object can
only be done from one thread at a time. Discussion
========== In this model, one can use a single FT_Library object across threads as
long as a mutex lock is used around FT_New_Face / FT_Done_Face. Any calls
to FT_Load_Glyph and similar API are safe and do not need the lock to be
held as long as the same FT_Face is not used from multiple threads at the
same time. Note that this goes almost all the way to making FreeType API useful from
multiple threads. The only remaining bit is the unfortunately API that is
FT_Library_SetLcdFilter (and to less extent FT_Library_SetLcdFilterWeights). I will try to work out a solution for replacing FT_Library_SetLcdFilter
using new FT_LOAD_* values. There seem to be quite a few bits available in
that space, so that work should happen soon.

文中指出,freetype是非多线程安全的,同时他对于使用多线程的环境下,提出了自己的使用安全模型,并给出了代码。

按照他的示例代码,我对sdl_ttf的源码进行修改,是sdl_ttf适应多线程。

最新文章

  1. BPM合同管理解决方案分享
  2. 使用Selector改变TextView的字体颜色textColor的方法
  3. parse_str怎么用php
  4. AngularJs的UI组件ui-Bootstrap分享(十四)——Carousel
  5. 关于启明星系统移除apppath配置,让系统自动获取路径来设置cookie的解决方法
  6. Git入门指南十一:Git branch 分支与合并分支
  7. C++编写Config类读取配置文件
  8. mysql导入数据库
  9. Visual Studio 2010 单元测试目录
  10. UVA 10020 Minimal coverage(贪心 + 区间覆盖问题)
  11. 遍历json创建树状表(首先的前提条件是要引入jquery的jquery treeTable插件)
  12. eShopOnContainers 看微服务⑤:消息通信
  13. mysql 开发基础系列22 SQL Model
  14. mybatis框架之foreach标签
  15. asp.net乱码问题
  16. Centos6.8 Mysql5.6 安装配置教程(转)
  17. git常用命令小记
  18. HTML meta标签总结,HTML5 head meta属性整理
  19. P2327 [SCOI2005]扫雷
  20. 【总结】前端框架:react还是vue?

热门文章

  1. 新书《深入应用C++11:代码优化与工程级应用》出版,感谢支持
  2. spark读取hdfs数据本地性异常【转】
  3. hive sequencefile导入文件遇到FAILED: SemanticException Unable to load data to destination table. Error: The file that you are trying to load does not match the file format of the destination table.错误
  4. Lintcode: Fast Power 解题报告
  5. 【Linux】svn添加用户
  6. kali kvm Requested operation is not valid: network 'default' is not active
  7. iOS APP版本更新跳转到App Store下载/更新方法
  8. 基于jQuery实现的腾讯互动娱乐网站特效
  9. VS2013代码调试:[7]如何避免调试时加载符号
  10. <低风险投资之路>读书笔记