作业-读者编写附加信号量
我有一个家庭作业问题,我真的不知道如何开始。
这是问题: “这个问题利用了名为 ReaderWriterAppender 信号量的新同步原语。与 ReaderWriter 信号量相同的规则适用于读取器和写入器,并为附加器添加了这些新规则:
1) 最多只能有一个附加器任何给定时间的信号量。
2)appender和write不能同时拥有信号量
3)读取可以在追加期间进行”
我需要自己实现它。
有一个给出的结构
typedef struct {
//structure here
} rwasem_t;
void rwalock_init(rwasem_t * rwa) {
}
void rwa_read_lock(rwasem_t * rwa) {
}
void rwa_write_lock(rwasem_t * rwa) {
}
void rwa_append_lock(rwasem_t * rwa) {
}
void rwa_append_unlock(rwasem_t * rwa) {
}
问题是,我不知道如何解决这个问题。我知道什么是读写器信号量,我知道如何实现使用它们,但我以前使用过它们,他们甚至不告诉我是否可以使用 API 或其他东西。 提前
谢谢 。 > 加西姆
I have a homework problem that I really don't know how to start.
Here is the question:
"This problem makes use of the new synchronization primitive called the ReaderWriterAppender semaphore. The same rules apply with respect to readers and writers as with ReaderWriter semaphore, with the addition of these new rules for an appender:
1) No more than one appender can have the semaphore at any given time.
2) An appender and write cannot own the semaphore at the same time
3) Reads can take place during an append"
I need to implement it on my own.
There is a structure given
typedef struct {
//structure here
} rwasem_t;
void rwalock_init(rwasem_t * rwa) {
}
void rwa_read_lock(rwasem_t * rwa) {
}
void rwa_write_lock(rwasem_t * rwa) {
}
void rwa_append_lock(rwasem_t * rwa) {
}
void rwa_append_unlock(rwasem_t * rwa) {
}
The problem is, I don't know how to approach the problem. I know what reader writer semaphore is, I know how to use them, and I have used them before. But I don't know how to implement them. They don't even tell me if I can use an API or anything. Basically, "implement it"
Thanks in advance,
Gasim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一些提示:
appender 和 read 有什么不同?
如果您只对附加程序使用读锁会怎样?举出一种不同的情况。
我可以在附加程序案例中再添加一个锁来防止出现 (2) 中的情况吗?
伪代码:
什么是“do_somethingX()”?
锁定的顺序重要吗?如果是,正确的顺序是什么?
Some hints:
What is the different of appender and read?
What if you just use a read lock for appender? Name one case they are different.
Can I have add one more lock in the appender case to prevent the case in (2)?
Pseudo code:
what is "do_somethingX()" ?
Is the order of locking important? If yes, what is the correct order?