views:

44

answers:

1

Hi all,

I'm looking for a C implementation of a concurrent stack (like Cilk THE protocol) that would allow the main thread to push and pop (the pop operation would be at the begining of the stack for example) and a distant thread to pop (this pop operation would be at the end of the stack) with every precaution that has to be taken.

If no code, any implementation advice would be appreciated.

Thx!

+1  A: 

I would take a regular stack and wrap the push and pop functions with mutexes.

In psuedo-C:

void push(void *data)
{
    acquire_lock(mutex);
    stack_push(data)
    release_lock(mutex);
}

Add error checking and salt to taste.

Nathon
In fact I'm looking for wait free or lock free implementation for HPC application so the mutex solution is to avoid (that's why I pointed the Cilk protocol)
claferri