出队时的奇怪现象(strange phenomenon while dequeuing)
我创建了一个队列矢量。 队列中有10个向量和大约1000个元素。 然后我尝试以循环方式将所有向量中的一个元素从队列中出列。 但我观察到一个非常奇怪的现象。 我看到一些向量有2个元素出列,有些没有。
struct pkt{ int data; int time; }; //Input queues are already filled with 1000 packets std::vector<std::queue<pkt>> per_port_input_queue; std::vector<std::queue<pkt>> per_port_output_queue; // Dequeing one element at a time in a round-robin fashion for(int i=0;i<5; i++) { decoded_pkt=per_port_input_queue[i].front(); send_to_output(decoded_pkt); per_port_input_queue[decoded_pkt.data].pop(); } void send_to_output(pkt decoded_pkt) { per_port_output_queue[decoded_pkt.data].push(decoded_pkt); }
您可以在下面找到观察到的输出和我的预期输出。
======================================================== Port I/p (t=0) (after dequing My 5 pkt) Expected result ======================================================== 0 1000 1000 999 1 1000 1000 999 2 1000 1000 999 3 1000 998 999 4 1000 1000 999 5 1000 1000 1000 6 1000 999 1000 7 1000 999 1000 8 1000 1000 1000 9 1000 999 1000
有人可以澄清为什么会发生这种情况以及如何避免这种情况。 在c ++中使用队列是否有问题
I have created a vector of queues. There are 10 vectors and around 1000 elements in the queue. Then I try to dequeue one element from the in a queue across all the vector in a round-robin fashion. But I observe a very strange phenomenon. I see that some of the vectors have 2 elements dequeued and some have none.
struct pkt{ int data; int time; }; //Input queues are already filled with 1000 packets std::vector<std::queue<pkt>> per_port_input_queue; std::vector<std::queue<pkt>> per_port_output_queue; // Dequeing one element at a time in a round-robin fashion for(int i=0;i<5; i++) { decoded_pkt=per_port_input_queue[i].front(); send_to_output(decoded_pkt); per_port_input_queue[decoded_pkt.data].pop(); } void send_to_output(pkt decoded_pkt) { per_port_output_queue[decoded_pkt.data].push(decoded_pkt); }
Below you can find the observed output and my expected output.
======================================================== Port I/p (t=0) (after dequing My 5 pkt) Expected result ======================================================== 0 1000 1000 999 1 1000 1000 999 2 1000 1000 999 3 1000 998 999 4 1000 1000 999 5 1000 1000 1000 6 1000 999 1000 7 1000 999 1000 8 1000 1000 1000 9 1000 999 1000
Can somebody clarify me why this occurs and how to avoid this. Is there some problem with using queues in c++
原文:
最满意答案
您可以为按钮的图层设置委托,并实现委托方法`displayLayer:'
-(void)displayLayer:(CALayer *)layer { UIGraphicsBeginImageContext(layer.frame.size); CGContextRef context = UIGraphicsGetCurrentContext(); UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(0.0, 0.0, CGRectGetWidth(layer.frame), CGRectGetHeight(layer.frame))]; [[UIColor whiteColor] setFill]; [ovalPath fill]; [[UIColor blackColor] setStroke]; ovalPath.lineWidth = 1; [ovalPath stroke]; UIImage *imageBuffer = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); layer.contents = (id)[imageBuffer CGImage]; }
You can set the delegate for your button's layer and implement the delegate method `displayLayer:'
-(void)displayLayer:(CALayer *)layer { UIGraphicsBeginImageContext(layer.frame.size); CGContextRef context = UIGraphicsGetCurrentContext(); UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(0.0, 0.0, CGRectGetWidth(layer.frame), CGRectGetHeight(layer.frame))]; [[UIColor whiteColor] setFill]; [ovalPath fill]; [[UIColor blackColor] setStroke]; ovalPath.lineWidth = 1; [ovalPath stroke]; UIImage *imageBuffer = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); layer.contents = (id)[imageBuffer CGImage]; }
相关问答
更多-
#import
CALayer *imageLayer = YourImageview.layer; [imageLayer setCornerRadius:5]; [imageLayer setBorderWidth:1]; [imageLayer setMasksToBounds:YES]; 通过增加半径将变得更圆满。 只要图像是一个正方形,您可以通过将一半宽度作为拐角半径获得一个完美的圆: [ima ... -
长方形与椭圆形的底部形状(Rectangle with oval bottom shape)[2023-11-01]
以下是使用伪元素最小化标记的此形状的响应版本: DEMO 输出: HTML:HomeCSS: div { position:relative; width:40%; height:100px; overflow:hidden; margin:10px auto; text-align:center; font-size:1.8em;text-transform:uppercase;line-height:90px;color:#ff ... -
使用以下类而不是图像视图。 RoundedCornerImageView imageView1; imageView1.setRadius(10); 这将使图像半径为10像素,您可以给出您想要的值,并将其作为您想要的形状。 试试。 祝一切顺利 :) public class RoundedCornerImageView extends ImageView { private int radius = 10; public RoundedCornerImageView(Context ...
-
像这样: #oval { width: 50px; height: 200px; background: red; border-bottom-right-radius: 50px 100px; border-top-right-radius: 50px 100px; position: relative; } 注意:我已经按照文章中的说明独立设置了角的属性: Border-radius:用CSS创建圆角! 。 见演示 。 Like so: #oval ...
-
假设“椭圆形”表示椭圆形,那么下面将创建一个从圆形到椭圆形的实体渐变: Delta=0.01; module connector (height,radius,eccentricity) { hull() { linear_extrude(height=Delta) circle(r=radius); translate([0,0,height - Delta]) linear ...
-
CSS div椭圆形(CSS div oval shape)[2023-04-26]
body {overflow-x:hidden} svg {left:47%; position:relative; top:-24%; transform:translate(-50%, - 50%); width:2000px;} body { overflow-x: hidden } svg { left: 47%; position: relative; top: -24%; transform: translate(-50%, -50%); wid ... -
以下是使用伪元素的CSS唯一解决方案:before和:after 。 更新小提琴 ul { list-style: none; counter-reset: step; } .progressbar li { position: relative; width: 60px; height: 40px; line-height: 35px; display: block; margin: 0 auto 10px auto; background-col ...
-
您可以为按钮的图层设置委托,并实现委托方法`displayLayer:' -(void)displayLayer:(CALayer *)layer { UIGraphicsBeginImageContext(layer.frame.size); CGContextRef context = UIGraphicsGetCurrentContext(); UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGR ...
-
问题是图像的背景是白色的,所以你需要做的就是 解: 你可以使用photoShop和 使用套索切割背景,使其透明 The problem is that the background of your image is white so what you need to do is Solution: You could use photoShop and Use the lasso to cut of the background so it will be transparent
-
你的一个问题是: for (int i = 2; i < 400; i += 2) { double angle = theta * i / circleVertexCount; x = (float) Math.cos(angle) * r; vertexData[i] = x + offSetX; } for (int i = 3; i < 404; i += 2) { double angle = Math.PI * 2 * i / circleVertexCount ...