Reputation: 9263
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!
Upvotes: 0
Views: 879
Reputation: 50971
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.
Upvotes: 1