首页 \ 问答 \ volatile array c ++(volatile array c++)

volatile array c ++(volatile array c++)

我有一个应用程序,其中包含指向MyObject对象的指针数组:

MyObject **arr;
arr= new MyObject*[10];

应用程序有两个线程,这些线程将创建和删除new MyObject()到数组arr 。 因此, arr[n]将一直在变化,但是MyObject本身并没有改变。

我应该声明:

volatile MyObject **arr;

或者我应该去:

MyObject ** volatile arr;

提前致谢


I have an application that has an array of pointers to MyObject objects:

MyObject **arr;
arr= new MyObject*[10];

The application has two threads, these threads will create and delete new MyObject() to array arr. Therefore arr[n] will be changed all the time, however the MyObject's themselves do not change.

Should I just declare:

volatile MyObject **arr;

Or should I go with:

MyObject ** volatile arr;

Thanks in advance


原文:https://stackoverflow.com/questions/6865001
更新时间:2023-02-14 08:02

最满意答案

首先,Amazon SQS是一个伪队列,可保证消息的可用性,但不保证FIFO时序的顺序。 如果您希望以这种方式工作,您必须在您的应用中实施排序逻辑。

回到你的问题,SQS必须在你的应用程序中进行轮询,以检查是否有新消息可用。 我使用setInterval()在应用程序中实现了这一点。 我会轮询队列中的物品,如果找不到物品,我会延迟下一次呼叫,并且如果发现某些物品,下一次呼叫将立即绕过setInterval() 。 这显然是一个非常原始的实施,你可以看看替代品。 在SQS中找到新项目时,服务器上的子进程如何处理NodeJS应用程序? 我想你可以在不使用NodeJS的情况下在BASH中作为一个观察者来实现子进程。 如果已经有一个模块,你也可以查看npm模块。

简而言之,您可以通过多种方式进行轮询,但如果您正在使用Amazon SQS,则必须以某种方式进行轮询。

我不确定这一点,但如果您希望收到物品通知,您可能需要查看Amazon SNS。


For a start, Amazon SQS is a pseudo queue that guarantees availability of messages but not their sequence in FIFO fashion. You have to implement sequencing logic into your app if you want it to work that way.

Coming back to your question, SQS has to be polled within your app to check if there are new messages available. I implemented this in an app using setInterval(). I would poll the queue for items and if no items were found, I would delay the next call and in case some items were found, the next call would be immediate bypassing the setInterval(). This is obviously a very raw implementation and you can look into alternatives. How about a child process on your server that pings your NodeJS app when a new item is found in SQS ? I think you can implement the child process as a watcher in BASH without using NodeJS. You can also look into npm modules if there is already one for this.

In short, there are many ways you can poll but polling has to be done one way or the other if you are working with Amazon SQS.

I am not sure about this but if you want to be notified of items, you might want to look into Amazon SNS.

相关问答

更多
  • 您的SQS ARN无效: "arn:aws:sqs:*:myarn" 。 您应该使用arn:aws:sqs::: 。 (你错过了 )。 如果您希望您的政策在多个地区有效,则地区名称可能会被替换为* 。 但是账户ID是强制性的,因为队列名称在AWS主账户和区域内是唯一的。 有关有效的SQS策略的示例,请参阅http://docs.aws.amazon.com/AWSSimpleQueueService/lates ...
  • 你应该有两个进程,一个将消息插入队列和你的工作线程。 典型的工作线程将如下所示: while(true) { $res = $client->receiveMessage(array( 'QueueUrl' => $url, 'WaitTimeSeconds' => 1 )); if ($res->getPath('Messages')) { foreach ($res->getPath('Messages') ...
  • 我几次遇到这个问题,但仍然不完全确定如何设置Celery来处理SQS。 事实证明,最新版本的Kombu和Celery很容易。 作为另一个答案中提到的BROKER_URL语法的替代方法,您可以简单地设置传输,选项,用户和密码,如下所示: BROKER_TRANSPORT = 'sqs' BROKER_TRANSPORT_OPTIONS = { 'region': 'us-east-1', } BROKER_USER = AWS_ACCESS_KEY_ID BROKER_PASSWORD = AWS_S ...
  • 是的,请转到此页面并按照说明构建您自己的SDK版本。 该页面标题为“ 构建特定服务和API版本”的部分将告诉您如何构建仅包含您感兴趣的服务的API版本。下载源代码后,构建SDK的命令仅包含SQS服务将是: node dist-tools/browser-builder.js sqs > aws-sdk-sqs.js 使用新信息进行编辑: 亚马逊现在提供在线服务,使您可以更轻松地创建自己的SDK版本: https : //sdk.amazonaws.com/builder/js/ Yes, go to th ...
  • 与IAM角色关联的临时凭证已到期,但在到期之前会刷新它们。 除非您的应用程序在到期时间到达时未正确检查更新的凭证,否则这不应该导致问题。 但问题中更重要的因素是您可能不熟悉SQS API的基础。 SQS不依赖经过身份验证的“连接”,因此没有可能会“丢失”的单个连接。 从技术上讲,任何人都可以“连接”到SQS,因为连接本身不是经过身份验证的。 SQS独立验证每个操作 - 每个长轮询请求,每个删除消息操作等都会在服务发生时由服务进行身份验证。 (如果认证失败,则只有单个请求失败。) 只要您的代码为其创建的每个请 ...
  • 您可以在IOT规则的SELECT语句中使用sql函数topic()。 像SELECT * as data, topic() as topic FROM 'your topic' IOT sql函数参考http://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-functions.html#iot-function-topic You can use the sql function topic() in the SELECT statement ...
  • 首先,Amazon SQS是一个伪队列,可保证消息的可用性,但不保证FIFO时序的顺序。 如果您希望以这种方式工作,您必须在您的应用中实施排序逻辑。 回到你的问题,SQS必须在你的应用程序中进行轮询,以检查是否有新消息可用。 我使用setInterval()在应用程序中实现了这一点。 我会轮询队列中的物品,如果找不到物品,我会延迟下一次呼叫,并且如果发现某些物品,下一次呼叫将立即绕过setInterval() 。 这显然是一个非常原始的实施,你可以看看替代品。 在SQS中找到新项目时,服务器上的子进程如何处 ...
  • 引用自: https : //docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-queue-message-identifiers.html 重要 在您的系统中,始终完全存储整个队列URL,因为Amazon SQS会在您创建队列时将其返回给您(例如, http://sqs.us-east-2.amazonaws.com/123456789012/queue2 )。 每次需要在请求中指定队列URL时,不要从其单独的组件 ...
  • 鉴于我使用的是通用消息格式,唯一的区别是一个队列配置为使用延迟,我可以使用相同的JMS侦听器来处理这两个队列吗? 您需要配置两个消息侦听器,以便它们可以同时处理消息,并且还需要将onmessage逻辑移动到公共处理程序(以重用相同的代码)。 两个消息侦听器重用相同的逻辑,但并行运行。 Given that I am using a common message format and the only difference is that one queue is configured to use a de ...
  • 做你想做的事情的方法是使用长轮询 - 而不是每秒不断轮询,你打开一个保持打开的请求,直到它超时或消息进入队列。 看一下ReceiveMessageRequest的文档 ReceiveMessageRequest req = new ReceiveMessageRequest() .withWaitTimeSeconds(Integer.valueOf(20)); // set long poll timeout to 20 sec // set other properties on the ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。