I want to print elements of array using single printf. The array is small (for example up to 10 elements), but each time I may have to print different number of first elements of array.
I know I can do this:
count = how_many_first_elements_i_need_this_time();
printf("array elements: ");
for (i = 0; i < count; ++i)
printf("%d ", array[i]);
printf("\n");
But this may lead to interleaving outputs of several printf executed at the same time by different threads, I suppose.
I can write huge switch to handle all possible cases, but it is ugly.
Any other suggestions?
stdout) against concurrent access, even if you'd print out all array's membere using one call toprintf().printfbut some kind of linux kernel printer which wraps the phrase I'm providing with some additional data: pid, time, etc., so I BELIEVE it does synchronization. This is the reason I demand singleprintfcall. I have usedprintfto make this question as simple as possible and to be useful for broader range of cases than mine.