我正在学校实验室工作,我们被指示为计数程序创建一个递归互斥锁.我写了一些代码(不起作用),但我认为这主要是因为我不明白使用递归互斥锁的真正想法.任何人都可以详细说明递归互斥锁应该做什么/看起来像什么?
一般注意:我不是要求答案,只是澄清一下递归互斥锁应该做什么.
此外,如果有人好奇,这里是这需要的代码.我正在编辑/实现的代码是recmutex.c.
recmutex.h
#include <pthread.h>
/*
* The recursive_mutex structure.
*/
struct recursive_mutex {
pthread_cond_t cond;
pthread_mutex_t mutex; //a non-recursive pthread mutex
pthread_t owner;
unsigned int count;
unsigned int wait_count;
};
typedef struct recursive_mutex recursive_mutex_t;
/* Initialize the recursive mutex object.
*Return a non-zero integer if errors occur.
*/
int recursive_mutex_init (recursive_mutex_t *mu);
/* Destroy the recursive mutex object.
*Return a non-zero integer if errors occur.
*/
int recursive_mutex_destroy (recursive_mutex_t *mu);
/* The recursive mutex object referenced by mu …Run Code Online (Sandbox Code Playgroud) 我本周五正在攻读CS考试,并且在这里遇到了一个障碍.问题要求我处理异常,然后使用两种不同的方法传播异常,但我的印象是它们是同一个东西.有人可以帮忙吗?练习题列在下面.
您将获得以下课程:
public class ReadData {
public void getInput() {
getString();
getInt();
}
public void getString() throws StringInputException {
throw new StringInputException();
}
public void getInt() throws IntInputException {
throw new IntInputException();
}
}
class StringInputException extends Exception {}
class IntInputException extends Exception {}
Run Code Online (Sandbox Code Playgroud)
上面的代码将导致getInput()方法中的编译错误.使用两种不同的技术重写getInput()方法:
Method 1 - Handle the exception
Method 2 - Propagate the exception
Run Code Online (Sandbox Code Playgroud)
以便代码编译.