Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Concurrent_Vector's push_back guarantees

robert_jay_gould
Beginner
204 Views
What guarantee's does Concurrent_Vector's push_back have? If I push items onto it, will they be inserted in order (temporally)?

say:
time 0 time 1
thread1 : pushA
thread2 : pushB pushC

is there a guarantee that C will be placed after A, and B (A and B's order with respect to each other isn't important)
Or I could end up with B-C-A for example?

On a side note the comment in concurrent_vector.h on line 623 for the compact method is outdated
//! Optimize memory usage and fragmentation. Returns true if optimization occurred.
void compact();


0 Kudos
1 Reply
Anton_M_Intel
Employee
204 Views
What guarantee's does Concurrent_Vector's push_back have? If I push items onto it, will they be inserted in order (temporally)?
say:
time 0 time 1
thread1 : pushA
thread2 : pushB pushC

is there a guarantee that C will be placed after A, and B (A and B's order with respect to each other isn't important)
Or I could end up with B-C-A for example?
It could end up with B-C-A unless you have a barrier between time 0 and time 1 (or tasks' relationship). So, without a synchronization of threads, the only guaranteed order is B-C.
But it's not guaranteed that they will have consecutive indexes since B-A-C is also possible. Such an assurance can be given by grow_by(2) call.

On a side note the comment in concurrent_vector.h on line 623 for the compact method is outdated
//! Optimize memory usage and fragmentation. Returns true if optimization occurred.
void compact();
Thanks, I'll fix it.
0 Kudos
Reply