What's 'reservation' in RISC-V's 'lr' instruction? - atomic

From 8.2 Load-Reserved/Store-Conditional Instructions chapter in RISC-V's unprivileged ISA Manual,
LR.W loads a word from the address in rs1, places the sign-extended value in rd, and registers a reservation set—a set of bytes that subsumes the bytes in the addressed word. SC.W conditionally writes a word in rs2 to the address in rs1: the SC.W succeeds only if the reservation is still valid and the reservation set contains the bytes being written.
What's the reservation in the description? How is it implemented in hardware? How does a Hart know if the reservation has been invalidated by another Hart?

Related

How Daedalus wallet identifies a valid cardano payment address?

When a Cardano address is entered for payment, Daedalus identifies it as a valid address immediately. Even if there is a single character change, it shows it as an invalid address. Were are these addresses stored and how it is identified as a valid address.
There are two verification mechanisms, giving a certain level of certainty it's a valid address.
First, the wallet software can check it's valid address discrimination: Cardano Shelley mainnet addresses start with addr...
Second, the address - being a bech32 encoded string - has a checksum. This checksum for the given string length is not fully bulletproof but in almost all cases allows an instant offline validation for the given address.

outlook EntryId syntax

I am writing a tool to backup my mails. In order to understand if I have already backed up a mail I use the entryID.
The Entry ID is however very very long and so I have problems in serializing my datastructure with JSON, using the entryID as index in a hash.
Furthermore I noticed that the first part of the entryID remains identic throughout all my mails. Therefore my suspect, that the first part identifies the Outlook Server, and the last part the e-mails themselves. Therefore there should no need to use the whole entryID to identify a single mail in my account.
Anybody knows the syntax of this entryID, I did not find nothing on the Microsoft Site, maybe I did the wrong query.
Thx a lot
Example of EntryID:
00000000AC032ADC2BFB3545BD2CEE24F67EAFF507000C7E507D761D09469E2B3AC3FA5E65770034EA28BA320000FD962E1BCA05E74595C077ACB6D7D7D30001C72579700000
quite long, isnt´t it ?
All entry ids must be treated as black boxes. The first 4 bytes (8 hex characters) are the flags (0s for the long term entry id). Next 16 bytes (32 hex characters) are the provider UID registered with the M

What are "Included Services" in a Service useful for?

I have a custom profile for a proprietary device (my smartphone app will be the only thing communicating with my peripheral) that includes two simple services. Each service allows the client to read and write a single byte of data on the peripheral. I would like to add the ability to read and write both bytes in a single transaction.
I tried adding a third service that simply included the two existing single byte services but all that appears to do is assign a UUID that combines the UUIDs for the existing services and I don't see how to use the combined UUID since it doesn't have any Characteristic Values.
The alternatives I'm considering are to make a separate service for the two bytes and combine their effects on my server, or I could replace all of this with a single service that includes the two bytes along with a boolean flag for each byte that indicates whether or not the associated byte should be written.
The first alternative seems overly complicated and the second would preclude individual control of notifications and indications for the separate bytes.
Is there a way to use included services to accomplish my goals?
It's quite an old question, but in case anyone else comes across it I leave a comment here.
Here are two parts. One is a late answer for Lance F: You had a wrong understanding of the BLE design principles. Services are defined on the host level of the BLE stack. And you considered your problem from the application level point view, wanting an atomic transaction to provide you with a compound object of two distinct entities. Otherwise why would you have defined two services?
The second part is an answer to the actual question taken as quote from "Getting Started with Bluetooth Low Energy" by Kevin Townsend et al., O'Reilly, 2014, p.58:
Included services can help avoid duplicating data in a GATT server. If a service will be referenced by other services, you can use this mechanism to save memory and simplify the layout of the GATT server. In the previous analogy with classes and objects, you could see include definitions as pointers or references to an existing object instance.
It's an update of my answer to clarify why there is no need for the included services in a problem stated by Lance F.
I am mostly familiar with BLE use in medical devices, so I briefly sketch the SIG defined Glucose Profile as an example to draw some analogies with your problem.
Let's imagine a server device which has the Glucose Service with 2 defined characteristics: Glucose Measurement and Glucose Measurement Context. A client can subscribe for notifications of either or both of these characteristics. In some time later the client device can change its subscriptions by simply writing to the Client Configuration Characteristic Descriptor of the corresponding characteristic.
Server also has a special mandatory characteristic - Record Access Control Point (RACP), which is used by a client to retrieve or update glucose measurement history.
If a client wants to get a number of stored history records it writes to the RACP { OpCode: 4 (Report number of stored records), Operator: 1 (All records) }. Then a server sends an indication from the RACP { OpCode: 5 (Number of stored records response), Operator: 0 (Null), Operand: 17 (some number) }.
If a client wants to get any specific records it writes to the RACP { OpCode: 1 (Report stored records), Operator: 4 (Within range of, inclusive), Operand: [13, 14] (for example the records 13 and 14) }. In response a server sends requested records one by one as notifications of the Glucose Measurement and Glucose Measurement Context characteristics, and then sends an indication from the RACP characteristic to report a status of the operation.
So Glucose Measurement and Glucose Measurement Context are your Mode and Rate characteristics, then you also need one more control characteristic - an analog of the RACP. Now you need to define a number of codes, operators, and operands. Create a structure whichever suits you best, for example, Code: 1 - update, Operator: 1 - Mode only, Operand: actual number. A client writes it to the control point characteristic. A server gets notified on write, interprets it, and acts in a way defined by your custom profile.

Get unique user ID for a webapp from MongoDB's ObjectID

I need to get a unique user ID identifying a user for a voice recording web app. In order to do this with minimum additional requirements, I am trying to use MongoDB's ObjectID to get this done. According to the official documentation, ObjectId is a 12-byte BSON type, constructed using:
a 4-byte value representing the seconds since the Unix epoch,
a 3-byte machine identifier,
a 2-byte process id, and
a 3-byte counter, starting with a random value.
The ObjectID 3 byte machine field is the first three bytes of the (md5) hash of the machine host name according to this answer. So shouldn't this be unique for a given machine?
However, the machine identifier does not seem to be what I thought it is.
--From Laptop--
56316c85 b47e28 f61a6 2b931
56316c89 b47e28 f61a6 2b934
--From a phone--
56316dc9 d75b48 ce1c4 9f2b3
56316dcb d75b48 ce1c4 9f2b4
--From the same Laptop--
56316f47 d75b48 ce1c4 9f2bd
56316f7e d75b48 ce1c4 9f2be
Can someone help me understand this? This is the same MongoDB being hosted locally (on the laptop) and being accessed once from a Phone's browser (which is on the same network) and once on the laptop.

How to search iOS Address book efficiently

My app has the ability of sharing its content between different instances of the app i.e. there is a button that lets me attach a document to an email and send it off to another user of the app. When they receive this file it opens up in their instance of the app. This is all working.
However, during the import of this data file, I need the app to add address book records to the address book unless the email address is already in the address book then it must just return the ABRecordRef.
I need to decide which approach is more efficient:
A - Loop through the entire address book creating an array of user defined objects with name and email address (which is all I require) and ABRecordRef. Then when the app is reading the attachment file XML it must check this NSArray each time.
B - Access the address book every time I encounter a contact in the attachment XML and search for it based on email address e.g. ABAddressBookCopyArrayOfAllPeople
Any other ideas?
Note: this applies to searching by e-mail address. If you are searching by name this does not apply.
For an arbitrarily sized address book with a fixed size number of addresses to lookup, searching the address book will be faster. This is because the initial cost of putting all the addresses into a hash is guaranteed to take at least linear (O(n)) time with respect to the number of addresses in the book while (assuming the address book is at least moderately efficien) lookup should be either logarithmic (O(ln(n)) or constant time (O(x)) depending on the implementation since you have a fixed number of addresses to check.
Edit:
A brief survey of the address book api shows that you can't simply "search the address book", you have to make a copy and then filter it.
Using Record Identifiers
Every record in the Address Book database has a unique record identifier. This identifier always refers to the same record, unless that record is deleted or the MobileMe sync data is reset. Record identifiers can be safely passed between threads. They are not guaranteed to remain the same across devices.
The recommended way to keep a long-term reference to a particular record is to store the first and last name, or a hash of the first and last name, in addition to the identifier. When you look up a record by ID, compare the record’s name to your stored name. If they don’t match, use the stored name to find the record, and store the new ID for the record.
To get the record identifier of a record, use the function ABRecordGetRecordID. To find a person record by identifier, use the function ABAddressBookGetPersonWithRecordID. To find a group by identifier, use the function ABAddressBookGetGroupWithRecordID. To find a person record by name, use the function ABAddressBookCopyPeopleWithName.
Given the limitations of the address book in iOS, copying the address book into a NSDictionary is going to be faster than trying to search each time.
Assuming you are fine with overwriting on email address collisions, I would create a dictionary with the email address as the key and the ABRecordRef stored as a NSNumber for the object.
I would do all this on a background queue and then monitor for address book changes and reload the dictionary as needed.
We've encountered users with several thousand entries in their address books. In those cases, you may want to create a record object and store it in Core Data. By filtering on the last modified date, you can determine whether or not to update the email addresses for a given record.