N
nass
this is a thought experiment.
i do not have the time to implement it and test it to see if it works
so i am relying on your good will
thank you in advance
im on a linux machine (slackware 10.2) on an i686 intell processor.
its my first attempt to convert a fileIO procedure, to a pthread so it
won't stall the execution of the code.
im going through an online tutorial
http://www.llnl.gov/computing/tutorials/pthreads/
that rightly suggests that when passing argument to a thread i should
generate an array and each thread will be given a reference to a cell
of this array. so far so good.
now fileIO procedure is called every 1-2 seconds but it could need to
go down to 100msec.. in any case i assume the worst case scenario that
one thread of fileIO is NOT completed before a next fileIO thread is
created.
now since the structure of data i pass in the thread is rather big , i
thought its best to use dynamic memory allocation instead of
initializing an constant array. assume the struct is
ThreadPass *pThrdArgs;
so i declare it as such.
in the constructor i say
pThrdArgs = new ThreadPass[1];
so as to allocate 1 structure in mem.
during execution and when the condition is met i do a
memcpy(pThrdArgs[pThrdIDindex],SensorData,sizeof(ThreadPass))
and i create the thread, run it and increment the pThrdIDindex. at the
very end of the thread execution i reset the
pThrdIDindex = 0 so that on the next fileIO procedure call,
pThrdIDindex will be either 0 (the thread has completed) or 1 in which
case it means it hasnt competed.
what i want to do is to check if the thread has finished execution (by
checking pThrdIDindex or any other means cause i know this way is not
bulletproof) and if it hasn't to somehow allocate space for
pThrdArgs[1], ie do
pThrdArgs = new ThreadPass[2];
or smth similar to allocate space for the next pThrdArgs, while still
keeping the data of the pThrdArgs[0] intact for the 1st thread call to
complete.
additionally and provided this can happen. how should i go about
deleting the pThrdArgs[0] data? will the pThrdArgs[1] remain alive?
thank you for your help
nass
i do not have the time to implement it and test it to see if it works
so i am relying on your good will
thank you in advance
im on a linux machine (slackware 10.2) on an i686 intell processor.
its my first attempt to convert a fileIO procedure, to a pthread so it
won't stall the execution of the code.
im going through an online tutorial
http://www.llnl.gov/computing/tutorials/pthreads/
that rightly suggests that when passing argument to a thread i should
generate an array and each thread will be given a reference to a cell
of this array. so far so good.
now fileIO procedure is called every 1-2 seconds but it could need to
go down to 100msec.. in any case i assume the worst case scenario that
one thread of fileIO is NOT completed before a next fileIO thread is
created.
now since the structure of data i pass in the thread is rather big , i
thought its best to use dynamic memory allocation instead of
initializing an constant array. assume the struct is
ThreadPass *pThrdArgs;
so i declare it as such.
in the constructor i say
pThrdArgs = new ThreadPass[1];
so as to allocate 1 structure in mem.
during execution and when the condition is met i do a
memcpy(pThrdArgs[pThrdIDindex],SensorData,sizeof(ThreadPass))
and i create the thread, run it and increment the pThrdIDindex. at the
very end of the thread execution i reset the
pThrdIDindex = 0 so that on the next fileIO procedure call,
pThrdIDindex will be either 0 (the thread has completed) or 1 in which
case it means it hasnt competed.
what i want to do is to check if the thread has finished execution (by
checking pThrdIDindex or any other means cause i know this way is not
bulletproof) and if it hasn't to somehow allocate space for
pThrdArgs[1], ie do
pThrdArgs = new ThreadPass[2];
or smth similar to allocate space for the next pThrdArgs, while still
keeping the data of the pThrdArgs[0] intact for the 1st thread call to
complete.
additionally and provided this can happen. how should i go about
deleting the pThrdArgs[0] data? will the pThrdArgs[1] remain alive?
thank you for your help
nass