0

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!

4
  • 1
    If you want to push at the beginning and pop at the end then it is no stack but a queue. Commented Jul 16, 2010 at 13:33
  • Did you want the consumer ('distant thread') to block when it reads and there's nothing in there yet? (blocking queue) Commented Jul 16, 2010 at 13:44
  • Also, what environment? POSIX? Win32? Commented Jul 16, 2010 at 13:45
  • yes sorry about that, ideally a queue or a deque would be great, wait free would be perfect. POSIX environnement. Commented Jul 16, 2010 at 14:12

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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)
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.