Page 1 of 1

starting thread with parameters...

Posted: Sun Apr 27, 2014 4:44 am
by jscott
I am getting ADC data from three ADC channels and doing some processing in the ADC callback. When my data buffer is ready, I switch buffers and need to send the full buffers to another thread for processing while the second set of buffers fill.

I have not been able to figure out how to start a thread with parameters.

Anybody got any ideas?

Thanks
-John Scott

Re: starting thread with parameters...

Posted: Sun Apr 27, 2014 8:19 am
by Giovanni
Hi,

The last parameter of thread create functions is a parameter that is passed to the created thread, if you need more than a parameter then you may use it to pass a pointer to a structure.

Giovanni

Re: starting thread with parameters...

Posted: Mon Apr 28, 2014 2:28 pm
by colin
Also, do you really want to start the other thread or just send it a message when the ADC conv is done? It it's happening constantly it would maybe make more sense to have the processing thread wait and receive via a mailbox or some other synchronization construct.

Re: starting thread with parameters...

Posted: Mon Apr 28, 2014 6:33 pm
by jscott
Colin,

Yea, I think just passing a message might be better.
That would solve the problem I have with defining
a thread in one module and creating the thread.

Giovanni,

How would I go about having one module named processing.c that contains a thread defined in the usual way. Then call the create process function from another module, for example main.c?

Normally I would just create prototypes in a header file, but don't know how to deal with the process working area.

In the past, I have just called a stub in the module with the thread, then started the thread locally.

-john Scott

Re: starting thread with parameters...

Posted: Mon Apr 28, 2014 7:43 pm
by Giovanni
Creating a separate module for the thread is a clean approach, no problems with that. In the header file put the thread function prototype and the re-declaration of the working area preceded by "extern".

The result, depending on the port, is something like:

extern stkalign_t myWA[1024];

Giovanni