多线程的坑

robot@robot:~/ck_test1_wjw $ rosrun yuyi location
Segmentation fault (core dumped)
robot@robot:~/ck_test1_wjw $ rosrun yuyi location
freeglut  ERROR:  Internal error <FBConfig with necessary capabilities not found> in function fgOpenWindow
robot@robot:~/ck_test1_wjw $ rosrun yuyi location
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
location: ../../src/xcb_io.c:179: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed.
Aborted (core dumped)
robot@robot:~/ck_test1_wjw $ rosrun yuyi location
[xcb] Extra reply data still left in queue
[xcb] This is most likely caused by a broken X extension library
[xcb] Aborting, sorry about that.
location: ../../src/xcb_io.c:576: _XReply: Assertion `!xcb_xlib_extra_reply_data_left' failed.
Aborted (core dumped)
robot@robot:~/ck_test1_wjw $ rosrun yuyi location
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
location: ../../src/xcb_io.c:179: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed.
Aborted (core dumped)
robot@robot:~/ck_test1_wjw $ rosrun yuyi location
^[[ASegmentation fault (core dumped)

加入多线程之后,也就是pthread_create,主函数的后面一定要跟一些循环语句。。。while(1)什么的。否则会出错。

https://blog.csdn.net/weixin_41931548/article/details/80802340多线程的讲解,加MFC的,挺不错

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
当涉及到多线程编程时,确实存在一些点。以下是几个常见的 Python 多线程: 1. 全局解释器锁(GIL):在 Python 中,由于 GIL 的存在,一个线程只能在一个时间点上执行 Python 代码。这意味着即使你有多个线程,你的代码也无法并行执行。因此,如果你想要充分利用多核 CPU,你需要使用多个进程而不是多个线程。 2. 竞争条件:多个线程同时访问共享资源可能会导致竞争条件。例如,如果两个线程同时尝试向同一个文件写入数据,可能会导致数据损坏或丢失。为了避免这种情况,你需要使用锁或其他同步原语来确保每个线程访问资源的顺序。 3. 内存泄漏:多线程应用程序中的内存泄漏可能比单线程程序更难以跟踪和调试。因为多个线程可以同时访问相同的内存地址,所以即使一个线程已经释放了一块内存,其他线程仍然可以访问它。为了避免这种情况,你需要确保在不再需要内存时正确地释放它。 4. 连接池的:当使用连接池时,你需要小心不要在多个线程之间共享连接。如果你的应用程序使用了多个线程,并且每个线程都尝试从连接池中获取连接,则可能会出现竞争条件。为了避免这种情况,你需要为每个线程使用独立的连接池。 总之,在使用 Python 进行多线程编程时,你需要小心处理这些点,并且确保你的应用程序在多线程环境下稳定和可靠。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mr.Naruto

你的鼓励是我的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值