临界区算法问题(Question on critical section algorithm)
“ 操作系统概念”第6版介绍了一种实现循环部分的算法。
do{ while (turn != i); critical section trun = j; remainder section } while(1);
注意 ,Pi是带有标识符i的过程,Pj是带有标识符j的过程。为了说明问题,本书将i,j限制为0和1,这两个过程构成了可靠的环境。
问题1是,这个算法是否说明了Progress要求,这是对于ciritical section解决方案的三个要求之一?
在我看来,当Pi处于其余部分时,它不能参与Pj是否可以进入临界区的决定,这是必然的。
或者我对进展要求的理解是完全错误的。因为如果Pi从剩余部分退出,它不能立即进入切片部分,这个阿尔格违反了规则。
问题2 ,
如果turn == 0且P1准备进入其关键部分,则P1不能这样做,即使认为P0可能在其余部分
这个陈述的含义是什么?就我所能想到的,我无法理解为什么turn == 0和p0在其余部分可能同时存在...
那么这个说法是错误的?
The Operating System Concepts 6th edition present one trival algorithm to implementate ciritical section.
do{ while (turn != i); critical section trun = j; remainder section } while(1);
Note,Pi is the process with identifier i,Pj is the process with identifier j.To simlify the question,the book limit the i,j to 0 and 1,the two processes constriant enviroment.
Question1 is,dose this algorithm voilate the Progress requirement which is one of the three requirements to ciritical section solution?
In my opinion,when Pi is in its remainder section,it cannot participate in the decision on whether Pj can enter the critical section.Then it is bound to the requirement.
Or my understanding of progress requirement is totally wrong.So because if Pi retired from the remainder section,It could not get into the cirtical section immediate,this alg violate the rule.
Question2,
If turn == 0 and P1 is ready to enter itscritical section,P1 cannot do so,even thought P0 may be in its remainder section
Whats the meaning of this statement?As far as I could think,I could not understand why turn == 0 and p0 be in its remainder section could be exist concurrently...
So is this statement wrong?
原文:https://stackoverflow.com/questions/1620311
最满意答案
您可以实现IValidatableObject接口
像这样的东西:
public class MyObject : IValidatableObject { public IList<AccountAddress> BulkOrderAddresses { get; set; } public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { if(BulkOrderAddresses == null && !BulkOrderAddresses.Length > 2) { yield return new ValidationResult("List should contain more than 2 items"); } } }
You could implement IValidatableObject Interface
Something like this:
public class MyObject : IValidatableObject { public IList<AccountAddress> BulkOrderAddresses { get; set; } public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { if(BulkOrderAddresses == null && !BulkOrderAddresses.Length > 2) { yield return new ValidationResult("List should contain more than 2 items"); } } }
相关问答
更多-
尝试在Create方法参数中排除Id [HttpPost] public ActionResultCreate([Bind(Exclude = "Id")], CityViewModel model) Try Excluding the Id in the Create method parameters [HttpPost] public ActionResultCreate([Bind(Exclude = "Id")], CityViewModel model)
-
MVC3自定义验证(MVC3 Custom validation)[2023-05-11]
您可以使用Count或Any : public override bool IsValid(object value) { var PhoneNumbers = value as List; if (PhoneNumbers != null) { return PhoneNumbers.Count() > 0; } return false; } 要么: public ... -
您需要使用自定义验证属性并使用它来装饰模型,而不是单个属性: [AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = true, Inherited = false)] public class MyCustomValidatorAttribute : ValidationAttribute { public override bool IsValid(object value) { // valu ...
-
Asp.net mvc 2自定义视图模型:验证属性在哪里?(Asp.net mvc 2 custom view model: where would the validation attributes go?)[2022-03-01]
您仍在验证最终返回数据库的数据。 因此,为了保持您的应用程序干燥 ,您最好将Buddy Classes用于原始模型。 编辑 注意:这与您的问题没有任何关系 我个人更喜欢将原始模型扩展为与“编辑”相关的任何内容,我更喜欢仅使用ViewModel进行“显示”(详细信息页面,列表页面等)。 示例:这是我的好友类,在其中我添加了一个“RegionName”属性,我在编辑页面显示中使用它,但它与数据库没有任何关系。 在将其操作为“数据库可用”数据之前,您可以对要验证的自定义输入数据执行类似操作。 我在数据库中使用Re ... -
我后来在SO上发现了一些类似的问题解决方案: 使用数据注释自定义模型验证依赖属性 属性级验证错误会阻碍类级验证的验证 简短的回答似乎是不可能的。 答案大小的答案是:这不是在MVC4框中,但似乎有足够的工作时间 I later found some similar problem solution approaches on SO: Custom model validation of dependent properties using Data Annotations Property-level val ...
-
您的GenericRequired实现仅适用于服务器端验证。 在创建ValidationAttribute的子类时,您只能获得开箱即用的服务器端验证。 为了使这个工作与客户端验证,你需要实现IClientModelValidator并添加一个jQuery验证器(向链接页面下方的指令)。 正如我在评论中所建议的那样,您可以改为将RequiredAttribute划分子类来获得您想要的内容,例如: public class GenericRequired : RequiredAttribute { pu ...
-
您可以实现IValidatableObject接口 像这样的东西: public class MyObject : IValidatableObject { public IList
BulkOrderAddresses { get; set; } public IEnumerable Validate(ValidationContext validationContext) { if(B ... -
将ReadOnlyCollection返回到包装您管理添加到的列表的世界。 Return a ReadOnlyCollection to the world wrapping your list which you manage the Adds to.
-
我可以在自定义模型绑定器中使用MVC验证属性吗?(Can I use MVC validation attributes within a custom model binder?)[2022-02-09]
我不确定这是否可能,但我可以说的一件事是,如果可能的话,那么默认模型绑定器的扩展点不会让它变得非常容易被发现。 我花了几个小时试图让这个工作无济于事。 代替使其工作,您可以使用Controller的TryValidateModel()方法。 I'm not sure whether this is possible or not, but one thing I can say is that if it is possible then the extension points for default m ... -
确保您正在调用base方法: protected override void OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext) { ContactFormViewModel contactFormViewModel = bindingContext.Model as ContactFormViewModel; if (!String.IsNullOrEmpty(co ...