[Interest] Executing a small function as a thread

Syam Krishnan syamcr at gmail.com
Tue Mar 17 17:22:30 CET 2015


On 03/17/2015 09:23 PM, Sze Howe Koh wrote:
>
>> Well, my situation already needs me to poll objects periodically.
>> The following is indicative of my problem:
>>
>> while(1)
>> {
>>     for(all_objects)
>>     {
>>        ret = object[i]->execute()
>>        if(ret == complete) all_objects.remove( object[i] );
>>     }
>>
>>     sleep(1ms);
>> }
>>
>> Now, object::execute() is supposed to get its work done by calling
>> do_something().
>> execute() should not block but do_something() is blocking. That's why I
>> need to call it in a separate thread.
>> Till do_something() completes, subsequent calls to execute() shall
>> return a value indicating that it's execution
>> is not complete, so that it will not be removed from the list of objects
>> (all_objects).
> Does execute() do anything else besides call do_something(), and does
> your while-loop do anything else before sleeping? If not, what you
> really want is for QtConcurrent::map() to call
> execute()/do_something() on every object in your container.

Well, it does a few things more. So I think I'll stick with 
QtConcurrent::run().
I'm coding now and I have a question. My do_something() function has the 
signature:


int32_t SomeClass::do_something( unsigned char *data, const 
std::vector<SomeType>& obj_list);

I do this:

unsigned char *my_data;
std::vector<SomeType> my_obj_list;
...
QFuture<int32_t> f = QtConcurrent::run( &SomeClassObj, 
&SomeClass::do_something, my_data, my_obj_list);

Now, my question is will this cause a copy of my_obj_list?

Syam



More information about the Interest mailing list