Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can you tranlate the following pseudocode to delphi and basm ?

10 views
Skip to first unread message

aminer

unread,
Dec 15, 2011, 11:32:47 AM12/15/11
to

Hello,

I have found the following pseudo code of a very efficient fifo queue
that doen't use any CAS
just an XADD , and i want to ask you if someone can translate it to
Delphi and basm .

Here it is:

pseudo-code for a mpmc bounded queue of doubles:
______________________________________________
struct cell { uint32_t ver; double state; };


uint32_t head = 0;
uint32_t tail = 0;
cell cells[N]; // N must be a power of 2


void init() {
for (uint32_t i = 0; i < N; ++i) cells.ver = i;



}


void producer(double state) {
uint32_t ver = XADD(&head, 1);
cell& c = cells[ver & (N - 1)];
while (LOAD(&c.ver) != ver) backoff();
c.state = state;
STORE(&c.ver, ver + 1);


}


double consumer() {
uint32_t ver = XADD(&tail, 1);
cell& c = cells[ver & (N - 1)];
while (LOAD(&c.ver) != ver + 1) backoff();
double state = c.state;
STORE(&c.ver, ver + N);
return state;

}

______________________________________________



And here is the link it's by invented by:


Chris M. Thomasson


here is his message on usenet on the following forum:

comp.programming.threads

http://groups.google.com/group/comp.programming.threads/browse_thread/thread/f9cab03871241455#



Best regards,

Amine Moulay Ramdane.

0 new messages