是std :: stack :: push和std :: stack:pop线程安全吗?(Are std::stack::push and std::stack:pop thread safe?)
我需要使用互斥锁保护我的
push()
和pop()
调用,还是内部线程安全?我想写的代码看起来像这样
parallel for (int i = 0; i < 100; i++) { ... s.push(...); ... }
我不知道在哪里查看我正在使用的STL容器的线程安全性。 我检查了这个参考 ,但没有提到任何关于线程安全的内容。
Do I need to guard my
push()
andpop()
calls with a mutex, or are they internally thread safe?The code I wish to write looks like this
parallel for (int i = 0; i < 100; i++) { ... s.push(...); ... }
I am not sure where to look about the thread safety of the STL containers I am using. I checked this reference, but it does not mention anything about thread safety.
原文:https://stackoverflow.com/questions/12251578
最满意答案
正如您在修改后的代码中所拥有的那样
zip(hexArray, initArray, function(x, y){ document.getElementById(x).addEventListener('animationend', y, false); document.getElementById(x).addEventListener('webkitAnimationEnd', y, false); });
y是一个字符串而不是一个变量。
但是你希望y成为一个函数对象
在设置inita,initb等之后放置以下内容,注意没有引号“
var initArray = [inita, initb, initc, initd, inite, initf, initg, inith, initi, initj, initk, initl, initm];
即
inita = function () { document.getElementById('hexa').className='wave'; }; initb = function () { document.getElementById('hexb').className='wave'; }; etc ... var initArray = [inita, initb, initc, initd, inite, initf, initg, inith, initi, initj, initk, initl, initm];
As you have it in your revised code in
zip(hexArray, initArray, function(x, y){ document.getElementById(x).addEventListener('animationend', y, false); document.getElementById(x).addEventListener('webkitAnimationEnd', y, false); });
y is a string not a variable.
However you want y to be a function object
place the following after you have set inita, initb etc noting that there are no quotes "
var initArray = [inita, initb, initc, initd, inite, initf, initg, inith, initi, initj, initk, initl, initm];
ie
inita = function () { document.getElementById('hexa').className='wave'; }; initb = function () { document.getElementById('hexb').className='wave'; }; etc ... var initArray = [inita, initb, initc, initd, inite, initf, initg, inith, initi, initj, initk, initl, initm];
相关问答
更多-
使用groupby()和.transform()你可以做如下的事情: df['flag'] = df.groupby('group')['url'].transform(lambda x: x.str.len() == x.map(len).max()) 它为df['flag']提供了一个布尔值。 如果你需要它作为0 ,那么只需将.astype(int)添加到最后。 Using groupby() and .transform() you could do something like: df['flag ...
-
使用apply重写循环(Rewrite loop using apply)[2023-03-01]
您的函数看起来只是从数组中每个单元格的值中减去目标值。 任何负值都替换为0.在这种情况下,您不需要任何循环,您可以使用R的内置向量化来执行此操作: set.seed(123) # If you have a data.frame of all numeric elements turn it into a matrix first df <- as.matrix( data.frame( matrix( runif(25) , nrow = 5 ) ) ) target <- 0.5 df # ... -
将函数应用于Eigen Matrix中的所有元素,无需循环(Apply function to all elements in Eigen Matrix without loop)[2022-11-20]
您可以将lambda表达式传递给unaryExpr ,如下所示: Eigen::Matrixnew_m = m.unaryExpr( [](const Foo& x) { return x.member_of_foo_returns_int(); }); 如果你不能使用c ++ 11,你需要编写一个小帮助函数: int func_wrapper(const Foo& x) { return x.member_of_foo_returns_int( ... -
尝试这个 : $.ajax({ ... success: function (items) { $.each(items.d, function (idx, item) { $('#eachBox'+idx).html ( ... '' ...
-
这个问题似乎是你在每个“刷新”上重新添加你的子元素,这会改变元素的顺序,并给出刷新多个元素的错觉。 您需要区分初始渲染和后续刷新。 我建议你从你的渲染函数中删除append ,而是在最后的for循环中处理append : // And finally we render all the elements on the page for(el in elements){ elements[el].render(elements[el]); elements[el].target.append(el ...
-
正如您在修改后的代码中所拥有的那样 zip(hexArray, initArray, function(x, y){ document.getElementById(x).addEventListener('animationend', y, false); document.getElementById(x).addEventListener('webkitAnimationEnd', y, false); }); y是一个字符串而不是一个变量。 但是你希望y成为一个函数对象 在设置in ...
-
您缺少匿名函数的花括号 这对我有用: checkchange <- function(x) { while((x[1] + x[2]) < 8) { x[1] <- sample(5,1) x[2] <- sample(5,1) } return(cbind(x[1],x[2])) ...
-
过度简化,与jQuery的事件系统相距甚远,但基本的想法就在那里。 http://jsfiddle.net/fJzBL/ var div = document.createElement("div"), prefix = ["moz","webkit","ms","o"].filter(function(prefix){ return prefix+"MatchesSelector" in div; })[0] + "MatchesSelector"; Element.p ...
-
打破for循环(Breaking a for loop)[2023-10-26]
问题是你在每次迭代循环时将Mindf重置为其初始(大)值, for (i in 1:length(x1)){ Mindf <- 200000000 ... } 所以if (!MinRow < Mindf)条件永远不会适用。 在else分支中发生的Mindf到MinRow的设置只是重置为循环顶部的初始值。 你可能想要 Mindf <- 200000000 for (i in 1:length(x1)) { ... } 这是寻找最小距离点的另一种方法 以矢量化方式转换为时间格式 x1 <- s ... -
虽然循环过早破坏(While loop breaking prematurely)[2022-11-05]
这是一个循环的危险条件: nextSegment = queue.shift()您期望一个undefined值来结束循环,但请注意,空字符串也将计算为false。 相反,我建议使用: while ((nextSegment = queue.shift()) !== undefined) { This is a dangerous condition for a loop: nextSegment = queue.shift() You're expecting a value of undefined t ...