使用Java AtomicStampedReference的算法可以被认为是非阻塞的吗?(Can algorithm using Java AtomicStampedReference can be considered non-blocking?)
我正在尝试使用Java实现此处所述的非阻塞二进制搜索树 。 该算法基于单世界CAS,但是:
状态和信息字段一起存储在CAS对象中。 因此,内部节点使用四个字的存储器。
我决定使用AtomicStampedReference来存储这些数据。 问题在于它
通过创建表示“盒装”[引用,整数]对的内部对象来维护标记引用。
这种结构的内部实施:
public boolean compareAndSet(V expectedReference, V newReference, int expectedStamp, int newStamp) { Pair<V> current = pair; return expectedReference == current.reference && expectedStamp == current.stamp && ((newReference == current.reference && newStamp == current.stamp) || casPair(current, Pair.of(newReference, newStamp))); }
对定义为:
private static class Pair<T> { final T reference; final int stamp; private Pair(T reference, int stamp) { this.reference = reference; this.stamp = stamp; } static <T> Pair<T> of(T reference, int stamp) { return new Pair<T>(reference, stamp); } }
这种实现是否仍然是非阻塞的?
还有一个额外的问题:什么使compareAndSet操作成为原子?
I'm trying to implement non-blocking binary search tree as described here using Java. This algorithm is based on single-world CAS but:
The state and info fields are stored together in a CAS object. Thus, an internal node uses four words of memory.
I decided to use AtomicStampedReference to store this data. The problem is that it
maintains stamped references by creating internal objects representing "boxed" [reference, integer] pairs.
Internal implementation of this structure:
public boolean compareAndSet(V expectedReference, V newReference, int expectedStamp, int newStamp) { Pair<V> current = pair; return expectedReference == current.reference && expectedStamp == current.stamp && ((newReference == current.reference && newStamp == current.stamp) || casPair(current, Pair.of(newReference, newStamp))); }
Pair defined as:
private static class Pair<T> { final T reference; final int stamp; private Pair(T reference, int stamp) { this.reference = reference; this.stamp = stamp; } static <T> Pair<T> of(T reference, int stamp) { return new Pair<T>(reference, stamp); } }
Is this implementation still non-blocking?
And the extra question: what's making this compareAndSet operation atomic ?
原文:https://stackoverflow.com/questions/23529087
最满意答案
Firebase有一个AuthError枚举,告诉您FirebaseException中每个ErrorCode的含义,文档位于: https ://firebase.google.com/docs/reference/unity/namespace/firebase/auth
要用西班牙语获取错误消息,我这样做:
public static string GetErrorMessage(Exception exception) { Debug.Log(exception.ToString()); Firebase.FirebaseException firebaseEx = exception as Firebase.FirebaseException; if (firebaseEx != null) { var errorCode = (AuthError)firebaseEx.ErrorCode; return GetErrorMessage(errorCode); } return exception.ToString(); } private static string GetErrorMessage(AuthError errorCode) { var message = ""; switch (errorCode) { case AuthError.AccountExistsWithDifferentCredentials: message = "Ya existe la cuenta con credenciales diferentes"; break; case AuthError.MissingPassword: message = "Hace falta el Password"; break; case AuthError.WeakPassword: message = "El password es debil"; break; case AuthError.WrongPassword: message = "El password es Incorrecto"; break; case AuthError.EmailAlreadyInUse: message = "Ya existe la cuenta con ese correo electrónico"; break; case AuthError.InvalidEmail: message = "Correo electronico invalido"; break; case AuthError.MissingEmail: message = "Hace falta el correo electrónico"; break; default: message = "Ocurrió un error"; break; } return message; }
Firebase has a AuthError enum that tells you the meaning of each ErrorCode in the FirebaseException, the documentation is here: https://firebase.google.com/docs/reference/unity/namespace/firebase/auth
To get the error message in Spanish I am doing this:
public static string GetErrorMessage(Exception exception) { Debug.Log(exception.ToString()); Firebase.FirebaseException firebaseEx = exception as Firebase.FirebaseException; if (firebaseEx != null) { var errorCode = (AuthError)firebaseEx.ErrorCode; return GetErrorMessage(errorCode); } return exception.ToString(); } private static string GetErrorMessage(AuthError errorCode) { var message = ""; switch (errorCode) { case AuthError.AccountExistsWithDifferentCredentials: message = "Ya existe la cuenta con credenciales diferentes"; break; case AuthError.MissingPassword: message = "Hace falta el Password"; break; case AuthError.WeakPassword: message = "El password es debil"; break; case AuthError.WrongPassword: message = "El password es Incorrecto"; break; case AuthError.EmailAlreadyInUse: message = "Ya existe la cuenta con ese correo electrónico"; break; case AuthError.InvalidEmail: message = "Correo electronico invalido"; break; case AuthError.MissingEmail: message = "Hace falta el correo electrónico"; break; default: message = "Ocurrió un error"; break; } return message; }
相关问答
更多-
Firebase身份验证目前存在问题。 在此处查看Firebase状态信息中心: https://status.firebase.google.com/ Firebase Authentication is having problems right now. Look at the Firebase Status Dashboard here: https://status.firebase.google.com/
-
使用服务帐户的Unity FireStation会挂起获取身份验证令牌(Firebase for Unity using service accounts hangs fetching auth token)[2023-08-19]
我在收到帮助请求后收到了Firebase的回复。 他们将在下一个版本中提供解决此问题的解决方案。 I received a response from Firebase after submitting a request for help. They will be including a fix for this problem in their next release. -
你没有返回Facebook.login() 。 所以我相信当你尝试在你的组件中访问它时它会返回错误。 return Facebook.login(['email', 'public_profile']).then(res => { You are not returning Facebook.login(). So I believe it returns error when you try to access it in your component. return Facebook.logi ...
-
React Native - Firebase身份验证持久性无法正常工作(React Native - Firebase auth persistence not working)[2022-03-02]
您不需要设置持久性。 Firebase默认为您处理它。 你只需要调用这个函数来检查用户是否登录。 firebase.auth().onAuthStateChanged((user) => { if (user) { console.log('user is logged'); } } 只有当用户注销或清除应用程序数据时才会触发此功能。 您可以在官方文档中找到更多详细信息: https : //firebase.google.com/docs/auth/web/man ... -
这是打字稿定义中的一个错误。 Firebase团队已收到通知,正在制定修复程序。 在此期间,请使用以下解决方法: (
firebase.auth.EmailAuthProvider).credential this is a bug in the typescript definitions. The Firebase team has been notified and is working on a fix. In the meantime use the following workar ... -
Unity3d中的Firebase身份验证+ Firebase存储(Firebase Authentication + Firebase Storage in Unity3d)[2021-12-16]
使用UnitySDK的Firebase身份验证现在无法在UnityEditor上运行。(也是独立的) https://github.com/firebase/quickstart-unity/issues/3 你是否只在UnityEditor上试过它? 它可能适用于iOS或Android。 但是,我也在寻找在Unity3D独立游戏中使用Firebase身份验证的方法。 在独立游戏中使用带有Unity的Firebase身份验证 如果您已经在iOS或Android上尝试过它然后问这个,我什么也没有了。 Fire ... -
在Firebase JavaScript SDK的2.x版本上,对React Native进行了身份验证,但在运行之间的任何位置都没有保留会话信息。 这样做的原因是React Native中没有本地存储(Firebase用于在浏览器中保存此信息)。 在Firebase JavaScript SDK 3.0版中,身份验证不再适用于React Native。 从Firebase JavaScript SDK 3.1版开始,身份验证再次在React Native上运行。 会话详细信息保留在React Native ...
-
Firebase Auth无法在Unity Editor上运行。 https://github.com/firebase/quickstart-unity/issues/3 Firebase Auth doesn't work on Unity Editor. https://github.com/firebase/quickstart-unity/issues/3
-
当用户登录时,您同时调用signInWithRedirect和getRedirectResult,这就是为什么您陷入无限循环: } else { firebase.auth().signInWithRedirect(provider); firebase.auth().getRedirectResult().then(function(result) { 您可以将signInWithRedirect附加到单击或将其从此块中拉出(用户未登录)块。 When the user is signed in ...
-
Firebase有一个AuthError枚举,告诉您FirebaseException中每个ErrorCode的含义,文档位于: https ://firebase.google.com/docs/reference/unity/namespace/firebase/auth 要用西班牙语获取错误消息,我这样做: public static string GetErrorMessage(Exception exception) { Debug.Log(exception.ToString()); ...