我正在尝试重现Dijkstra在题为"协作顺序进程"的文章中编写的ALGOL 60代码,代码是第一次尝试解决互斥问题,这里是语法:
begin integer turn; turn:= 1;
parbegin
process 1: begin Ll: if turn = 2 then goto Ll;
critical section 1;
turn:= 2;
remainder of cycle 1; goto L1
end;
process 2: begin L2: if turn = 1 then goto L2;
critical section 2;
turn:= 1;
remainder of cycle 2; goto L2
end
parend
end
Run Code Online (Sandbox Code Playgroud)
所以我试着在Promela中重现上面的代码,这是我的代码:
#define true 1
#define Aturn true
#define Bturn false
bool turn, status;
active proctype A()
{
L1: (turn == 1);
status = Aturn; …Run Code Online (Sandbox Code Playgroud) 我读过这篇与Go完全无关的有趣博客文章,作者说过的一件事引起了我的注意,以下引用:
...例如,将通道作为函数all的参数传递是有效的,因为Go中的通道与指向C中实现的通道数据结构的指针一样简单.对于地图和其他一些通道是相同的类型.但传递数组或结构是低效的; 相反,我们应该将指针传递给这些类型.
使用Go内部类型或结构时,为什么传递指针效率不高?
所以我run在angularjs中有这个功能(运行AngularJS v1.2.26)
.run(function(....) {
authService.authCheck();
$rootScope.$on('$routeChangeStart', function(event, next, current) {
if (next.requireLogin) {
if (!authService.isLoggedIn()) {
$location.path('/login');
event.preventDefault();
}
}
});
})...
Run Code Online (Sandbox Code Playgroud)
当直接访问需要身份验证的URL时,例如http://127.0.0.1:8080/secret,该函数总是重定向到登录路径,在调试它一段时间后,它会一直评估为false.访问默认页面然后转到指定的路由它运行没有任何问题.
这是我的一部分 authService
this.authCheck = function() {
$http({
method: 'PUT',
url: '/api/login'
}).
success(function(data, status, headers, config) {
if (status === 200) {
userIsAuthenticated = true;
} else {
userIsAuthenticated = false;
}
$rootScope.loginStatus = userIsAuthenticated;
}).
error(function(data, status, headers, config) {
userIsAuthenticated = false;
$rootScope.loginStatus = userIsAuthenticated;
});
};
this.isLoggedIn = function() { …Run Code Online (Sandbox Code Playgroud) 对于变量初始化,Go有多少不同的方式让人难以置信.也许我完全不理解这一点,或者Go是一个很大的想法.很多东西感觉并不自然,看起来他们添加了功能,因为他们发现它们丢失了.初始化就是其中之一.
这是我的理解
var =或启动:=.:= 仅适用于方法内部&.它们只适用于复合类型.=或:=是否有任何简单的方法来了解新手的所有这些?阅读规范在所有地方都可以得到所有这些.