I'd like to know how to use _beginthread and _endthread to create a new parallel process.
I have to put the "read_audio" process running on background until a "ctrl_signal" comes, and so I create the "create_read_audio_process" thread to call the "read_audio" from that (in a buckle). The matter is that I have to pass 3 parameters to "read_audio" and so, I need these 3 parameters in the _beginthread function, and I do not know how to do it. Somebody knows how to solve it?
You are ok when you say I would have to learn more about threads, but the fact is that I only want to use 2 processes. One will fill a buffer with data (asynchronously) and will active a parameter to indicate that a buffer block is ready to be read, and the other one will read these blocks, So, I thought that I will not have problems with memory access (or am I wrong...?). In this case, it is not enough starting and ending a thread in the way I have explained?
If your going to have 2 threads. And 1 thread won't do anything til the first thread is finished then this is not a threading problem. There is nothing gained, and no point in having the problem threaded.
Threading is only useful when you want 2 things to happen concurrently.
I think you have not understood, Zaita. A thread will be reading the audio card continuously, and each time it fills a block, a the value of a variable will be changed. The other thread will sometimes check the value of this variable, and depending on its value, it will do one thing or other thing. Meanwhile, the first thread continues filling the buffers.
Going back to the initial question, is it possible to pass more than one parameter to the function _beginthread?
_beginthread takes one parameter. But you use it to pass a pointer to a structure with many fields.
The code below illustrates the point. It's not seen a compiler, so ...
Also, I've used _beginthreadex rather than _beginthread, but as someone mentioned in another thread, you may want to use something from a thread library (such as Boost), but you have to suffer the drawbacks.
its a bit risky to do like this, the reason for this is that dostuff can exit before the thread ends making params invalid.
one way around it is to create a copy of the argument in your thread function or to post the data as a message to the thread, that way you have the mechanics to update the thread parameters during run-time.