在向设备发送数据时,UNIX的原子性read()/ write()(Atomicity of UNIX read()/write() when sending data to device)
当直接写入/ dev中的设备时,我打开文件描述符并执行UNIX write(),然后执行read()。 我可以在同一文件描述符上有多个线程执行此write()/ read()序列,如果两个线程同时进入write()函数,则不会获得混乱数据吗?
对std文档的引用将非常有用。 虽然我找不到任何东西。 有人提到过这样的操作在内核中是原子的,但我持怀疑态度。
另外,为了澄清这是/ dev中的文件,因此任何关于“文件指针”概念在多大程度上应用的见解也是有帮助的。
When writing directly to a device in /dev, I open a file descriptor and perform a UNIX write() followed by a read(). Can I have multiple threads doing this write()/read() sequence on the same file descriptor, and not get jumbled data if two threads enter the write() function at the same time?
References to std documentation would be immensely helpful. I've not been able to find anything though. Someone has mentioned that such operations are atomic in the kernel, but I am sceptical.
Also, to clarify this is a file in /dev, so any insight as to how far the "file pointer" concept applies here is helpful as well.
原文:https://stackoverflow.com/questions/18411031
最满意答案
你想创建一个类有几个原因:
- 强大的打字功能利用编译器确保正确性。
- 每个封装数据的类都像一个合同 。 你可以想象通过检查课堂是如何使用的。
- 在你之后强迫这个人阅读它是如何工作的。 读取类属性并将其实用程序映射为更简单。
- 这是一个糟糕的规划和工程标志。 您正在创建数据块而不是解决特定问题的结构化数据集。 认为泥坑与乐高积木。
这份名单始终无限。 我认为这里的共识是避免它。 在极其罕见的情况下,这很有用。 对于大多数人来说,坚持契约和编码抽象而不是实现细节。
There are several reasons why you want to create a class:
- Strong typing leverages the compiler to ensure correctness.
- Every class that encapsulates data is like a contract. You can imagine how's used by examining the class.
- You force the guy after you to read how it works. It is simpler to read class properties and image its utility.
- It is a sign a bad planning and engineering. You are creating blobs of data instead of structured data sets that solve a specific problem. Think mud pits versus Lego blocks.
The list goes on ad infinitum. I think the consensus here is to avoid it. There are extreme rare cases where this is useful. For most, stick to contracts and coding to abstractions not implementation details.
相关问答
更多-
for (i = 0; i>10; i++){ 应该 for (i = 0; i<10; i++){ for (i = 0; i>10; i++){ should be for (i = 0; i<10; i++){
-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
您可以创建一个对所有文档类型都通用的服务(返回构造函数的工厂)。 在该函数内部,您可以使用angular.extend来扩展传递数据的默认值。 还要注意命名,例如不要使用document以避免与浏览器文档对象发生命名冲突。 这就是我将它命名为myDocument的原因。 要创建扩展工厂,可以在工厂函数中使用依赖项注入并扩展基础(请参阅imageService代码作为示例)。 请看下面的演示或这个jsfiddle 。 angular.module('demoApp', []) .factory('con ...
-
在新的ES2015标准 (以前称为ES6)中,可以使用计算键创建对象 : Object Initializer spec 。 语法是: var obj = { [myKey]: value, } 如果应用于OP的场景,则会变成: stuff = function (thing, callback) { var inputs = $('div.quantity > input').map(function(){ return { [this.attr('name')]: thi ...
-
动态对象创建(Dynamic Object creat)[2024-03-03]
通过java反射: String[] objectNameArray; objectNameArray = objectName.split("."); try { Class> clazz = Class.forName(objectNameArray[1]); Object context = getContext(); Constructor> constructor = clazz.getConstructor( ... -
使用括号语法: obj.assignment[str] = new Object(); 附注:您可以使用快捷方式{}来创建新对象。 例如: obj.assignment[str] = {}; Use the brackets syntax: obj.assignment[str] = new Object(); Side note: you can use the shortcut {} to create new objects. For example: obj.assignment[str] = ...
-
你想创建一个类有几个原因: 强大的打字功能利用编译器确保正确性。 每个封装数据的类都像一个合同 。 你可以想象通过检查课堂是如何使用的。 在你之后强迫这个人阅读它是如何工作的。 读取类属性并将其实用程序映射为更简单。 这是一个糟糕的规划和工程标志。 您正在创建数据块而不是解决特定问题的结构化数据集。 认为泥坑与乐高积木。 这份名单始终无限。 我认为这里的共识是避免它。 在极其罕见的情况下,这很有用。 对于大多数人来说,坚持契约和编码抽象而不是实现细节。 There are several reasons w ...
-
创建一个对象,并手动设置其密钥。 var tmp = {}; tmp[k] = v; 在ECMAScript 6中,您将能够直接在对象声明中执行此操作: var tmp = { [k] = v }; Create an object, and set its key manually. var obj = {} obj[key] = value Or using ECMAScript 2015 syntax, you can also do it directly in the object de ...
-
您可以为Pet编写__init__()以接受Animal的实例(或者实际上,任何具有必要属性的ojbect - duck typing!)以及各个属性。 然后你可以做fluffy_as_pet = Pet(fluffy_as_animal) 。 或者提供一个类方法(例如Pet.from_object() )来做同样的事情,如果你不想重载__init__() 。 即使您不控制Animal和Pet类,也可以根据需要创建自己的子类。 但是,最好更进一步,不要编写接受Animal但不接受Pet代码。 然后你不必转换 ...
-
您可以使用以下代码。 使用这些名称空间 using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Client; #region GetOrganizationService public static IOrganizationService GetOrganizationService() { try { IOrganizationService organizationService = null; Uri uri = n ...