开发者

Multithreaded data structure : concurrent stack

开发者 https://www.devze.com 2023-01-08 02:12 出处:网络
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 examp开

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 examp开发者_如何学编程le) 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!


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消