Qt shared_ptr signal with QThreadPool

时间:2017-08-30 20:48:32

标签: c++ multithreading qt

I'm trying to process large csv data as it comes in chunk. If I run chunkprocess without threading, the application doesn't crash. However, as soon as I add in the threadpool, the application crashes and throws in the following errors. ChunkProcess run only emits (nothing else yet) signal shared_ptr which is a private member of ChunkProcess. After reading articles online, I found that shared_ptr is not thread safe unless you make a copy of it... so is there a way i can make a copy of it while using it as a signal?

SELECT 
  List,of,columns,that,will,form,row,headers, 
    List,of,row,values,that,form,column,headers
FROM (
  select query that pulls ONLY the data you need for 
  row headers, column headers, and the columns you want to summarise
)tablealias
PIVOT
(
  SUM/AVG/MIN/MAX/etc(column to summarise) 
  FOR category IN (List,of,row,values,that,form,column,headers)
) AS pvt;

void SwapRightMostNBits(unsigned int& a, unsigned int& b, unsigned int n){

    unsigned int mask=(1U<<n) -1;
    unsigned int diff = (a^b) & mask;

    a ^= diff;
    b ^= diff;
}

1 个答案:

答案 0 :(得分:1)

ASSERT: "!d->ref.isShared()" in file tools\qlist.cpp, line 162

这意味着QListData(QList的私有部分)中的断言失败。这与shared_ptr无关。 Qt source并未澄清此断言所检查的内容,但我猜测您在QList上做了非法行为,或者您有某种竞争条件。 由于您没有显示相关的代码部分,因此很难说清楚。

QObject::~QObject: Timers cannot be stopped from another thread

这意味着您的QObject(最可能是ChunkProcessor)会从另一个线程中销毁,并且此对象有一个活动的计时器正在运行。

假设这是ChunkProcessor的问题,您可以通过以下几种方式解决问题:

  1. 请勿在{{1​​}}
  2. 中使用计时器
  3. 不要将ChunkProcessor的所有权转移到广告资源池(ChunkProcessor应该返回autoDelete()
  4. 注意崩溃与false无关!

    还有问题是您注册shared_ptr作为类型吗? 如果您没有通过信号槽机制(因为您使用了自动连接类型),那么它就没有了!