473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

va_lists and threads

The function f gets variable arguments and creates several threads
which each shall receive all of the variable arguments. Like so:

void f(
my_callback* array_of_callbacks,
...){

va_list va;
va_start(va,array_of_callbacks);

/* now loop through array */

/* create thread for each callback
and pass va for each callback
*/

/* end of loop */

va_end va;

}

(1) Is it ok to use the locally created va and return from f() even
though the threads may still run and access va?

(2) Is it ok to va_start va *only once* for all callbacks/threads in the
loop or do I have to provide copies like va1, va2, va3 for each
iteration? This would make thinks complicated since the count is
variable: I would have to dynamically create an array of va -- who
would finalize them, however?

Felix
Jan 5 '07 #1
2 2156

Felix Kater wrote:
The function f gets variable arguments and creates several threads
You'll probably get plenty of pointers that you are off-topic here.
The C language does not consider the possibility of multiple threads.

However, you are almost certainly looking to abuse the variable
arguments functionality. Read the language/library specification for
C89 (draft available free in pdf format online) and you see
stipulations such as "each invocation of va_start or va_arg shall be
matched by a corresponding invocation of va_end in the same function".
You also see that va_arg is defined as modifying the va_list object, so
sharing this is clearly unsafe.

Why not tell us a little more about what you are trying to do, and
we'll see whether we can help you achieve it in a robust manner, or
possibly we'll point you at a threads programming newsgroup.

Jan 5 '07 #2

Felix Kater wrote:
The function f gets variable arguments and creates several threads
which each shall receive all of the variable arguments. Like so:

void f(
my_callback* array_of_callbacks,
...){

va_list va;
va_start(va,array_of_callbacks);

/* now loop through array */

/* create thread for each callback
and pass va for each callback
*/

/* end of loop */

va_end va;

}

(1) Is it ok to use the locally created va and return from f() even
though the threads may still run and access va?

(2) Is it ok to va_start va *only once* for all callbacks/threads in the
loop or do I have to provide copies like va1, va2, va3 for each
iteration? This would make thinks complicated since the count is
variable: I would have to dynamically create an array of va -- who
would finalize them, however?

I think using a separate va_list object
for each callback would be fine.

--
aegis

Jan 6 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ronan Viernes | last post by:
Hi, I have created a python script (see below) to count the maximum number of threads per process (by starting new threads continuously until it breaks). ###### #testThread.py import...
0
by: Al Tobey | last post by:
I was building perl 5.8.2 on RedHat Enterprise Linux 3.0 (AS) today and noticed that it included in it's ccflags "-DTHREADS_HAVE_PIDS." I am building with -Dusethreads. With newer Linux...
6
by: m | last post by:
Hello, I have an application that processes thousands of files each day. The filenames and various related file information is retrieved, related filenames are associate and placed in a linked...
34
by: Kovan Akrei | last post by:
Hi, I would like to know how to reuse an object of a thread (if it is possible) in Csharp? I have the following program: using System; using System.Threading; using System.Collections; ...
7
by: Mr. Mountain | last post by:
In the following code I simulate work being done on different threads by sleeping a couple methods for about 40 ms. However, some of these methods that should finish in about 40 -80 ms take as long...
10
by: [Yosi] | last post by:
I would like to know how threads behavior in .NET . When an application create 4 threads for example start all of them, the OS task manager will execute all 4 thread in deterministic order manes,...
3
by: mjheitland | last post by:
Hi, I like to know how many threads are used by a Threading.Timer object. When I create a Threading.Timer object calling a short running method every 5 seconds I expected to have one additional...
10
by: Darian | last post by:
Is there a way to find all the thread names that are running in a project? For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and T5 are running...I want to be able to know that...
4
by: Ross | last post by:
Hi, I have a question about using va_lists. I have a pair of text formatting functions defined as follows: void fmt1(char *format,va_list l) { // ... } void fmt2(char *format,...) {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.