claf
claf

Reputation: 9263

Multithreaded data structure : concurrent stack

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

Answers (2)

claf
claf

Reputation: 9263

The NOBLE Library seems to be what I was looking for.

Upvotes: 0

nmichaels
nmichaels

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

Related Questions