https://www.liblfds.org/mediawiki/index.php?title=r6.1.0:Lfds610_stack&feed=atom&action=historyr6.1.0:Lfds610 stack - Revision history2024-03-28T21:12:42ZRevision history for this page on the wikiMediaWiki 1.36.0https://www.liblfds.org/mediawiki/index.php?title=r6.1.0:Lfds610_stack&diff=248&oldid=prevAdmin: 1 revision imported2015-01-04T14:07:32Z<p>1 revision imported</p>
<p><b>New page</b></p><div>{{DISPLAYTITLE:r6.1.0:lfds610_stack}}<br />
==Source Files==<br />
/liblfds610/src/lfds610_stack/lfds610_stack_delete.c<br />
/liblfds610/src/lfds610_stack/lfds610_stack_new.c<br />
/liblfds610/src/lfds610_stack/lfds610_stack_push_pop.c<br />
/liblfds610/src/lfds610_stack/lfds610_stack_query.c<br />
/liblfds610/src/lfds610_stack/lfds610_stack_internal.h<br />
/liblfds610/inc/liblfds610.h<br />
<br />
==Incomplete Types==<br />
struct lfds610_stack_state;<br />
<br />
==Enums==<br />
enum lfds610_stack_query_type<br />
{<br />
LFDS610_STACK_QUERY_ELEMENT_COUNT,<br />
LFDS610_STACK_QUERY_VALIDATE<br />
};<br />
<br />
==Prototypes==<br />
int [[r6.1.0:lfds610_stack_new|lfds610_stack_new]]( struct lfds610_stack_state **ss, lfds610_atom_t number_elements );<br />
void [[r6.1.0:lfds610_stack_use|lfds610_stack_use]]( struct lfds610_stack_state *ss );<br />
void [[r6.1.0:lfds610_stack_delete|lfds610_stack_delete]]( struct lfds610_stack_state *ss,<br />
void (*user_data_delete_function)(void *user_data, void *user_state),<br />
void *user_state );<br />
<br />
void [[r6.1.0:lfds610_stack_clear|lfds610_stack_clear]]( struct lfds610_stack_state *ss,<br />
void (*user_data_clear_function)(void *user_data, void *user_state),<br />
void *user_state );<br />
<br />
int [[r6.1.0:lfds610_stack_push|lfds610_stack_push]]( struct lfds610_stack_state *ss, void *user_data );<br />
int [[r6.1.0:lfds610_stack_guaranteed_push|lfds610_stack_guaranteed_push]]( struct lfds610_stack_state *ss, void *user_data );<br />
int [[r6.1.0:lfds610_stack_pop|lfds610_stack_pop]]( struct lfds610_stack_state *ss, void **user_data );<br />
<br />
void [[r6.1.0:lfds610_stack_query|lfds610_stack_query]]( struct lfds610_stack_state *ss, enum lfds610_stack_query_type query_type, void *query_input, void *query_output );<br />
<br />
==Overview==<br />
This API implements a stack. A new stack is instantiated by the ''lfds610_stack_new'' function, where the argument ''number_elements'' is the maximum number of elements which can be pushed to the stack at any one time. The caller then uses the stack by pushing and popping, via the ''lfds610_stack_push'' and ''lfds610_stack_pop'' functions, respectively. A push or pop operation will push or pop a single void pointer of user data. These void pointers are expected to point to user allocated state although of course they can be used directly to store a single value. Finally, the stack is deleted using ''lfds610_stack_delete''.<br />
<br />
The function ''lfds610_stack_push'' only fails when there are no elements available in the stack. In this case, the function ''lfds610_stack_guaranteed_push'' can be called. This allocates a single new element and then pushes that element. This permanently increases the maximum number of elements in the stack by one. This function only fails when ''malloc'' fails.<br />
<br />
==Lock-free Specific Behaviour==<br />
The maximum number of elements in the stack must be specified when the stack is created and these elements are allocated in full when the stack is created. It is possible after the stack is created to increase the number of elements in the stack, by using the function ''lfds610_stack_guaranteed_push'', but it is never possible to decrease the number of elements in the stack; the stack can only grow.<br />
<br />
==Algorithm==<br />
This freelist implements Treiber's stack algorithm. As such it does not truly scale; contention for entry and exit to and from the stack ultimately reduces performance as the CPU count increases. Indeed, with enough CPUs, performance becomes ''less'' than with fewer CPUs, for there are so many threads, they almost always fail in their attempt to enter or leave the stack and so are prevented from doing other work.<br />
<br />
There is a far more scalable stack, based on the work done by Hendler, Shavit and Yerushalmi, which I understand (I've not looked at in depth) is basically the Treiber stack but with a layer in front of the stack where any threads which at the same time wish to push and pop can exchange their respective operations (the pusher giving his element to the popper) and so avoid having to touch the stack. I intend to implement this in the future.</div>Admin