首页 \ 问答 \ 函数和数据指针如何允许c中的临时运行时多态性?(How function and data pointers permit ad hoc run-time polymorphism in c?)

函数和数据指针如何允许c中的临时运行时多态性?(How function and data pointers permit ad hoc run-time polymorphism in c?)

关于C的维基百科文章指出, Function and data pointers permit ad hoc run-time polymorphism

请解释一下这个是什么意思?


wikipedia article on C states that Function and data pointers permit ad hoc run-time polymorphism.

what is the meaning of this?please explain.


原文:https://stackoverflow.com/questions/11733169
更新时间:2023-05-30 06:05

最满意答案

(1)不,消费者没有锁; 它只是在请求满足之前被阻塞,但队列仍然可用。 如果有多个消费者,那么这个消费者就是潜在的收件人; 解析函数将选择满意的顺序。

(2)任何性能差异取决于实施。 不要问我们 - 你有最重要的权力在你面前:你的电脑。 使用您选择的测试场景和timeit工具。


(1) No, the consumer is not holding a lock; it's merely blocked until the request is satisfied, but the queue is still available. If there are multiple consumers, then this one is in the pool of potential recipients; the resolution function will choose the order of satisfaction.

(2) Any performance difference depends on the implementation. Don't ask us -- you have the foremost authority in front of you: your computer. Use a test scenario of your choice, and the timeit facility.

相关问答

更多
  • Queue.Queue和collections.deque具有不同的用途。 Queue.Queue旨在允许不同的线程使用排队的消息/数据进行通信,而collections.deque只是用作数据结构。 这就是为什么Queue.Queue具有put_nowait() , get_nowait()和join() ,而collections.deque则没有。 Queue.Queue不是用作集合的,这就是为什么它缺少in操作符。 它归结为:如果你有多个线程,并希望他们能够通信而不需要锁定,那么你正在寻找Queue ...
  • 如果你想知道你的所有线程是否都在工作,你可以在每次启动任务时打印线程名称: from threading import Thread from queue import Queue import random import time class DownloadWorker(Thread): def __init__(self, queue): Thread.__init__(self) self.queue = queue def run(self) ...
  • (1)不,消费者没有锁; 它只是在请求满足之前被阻塞,但队列仍然可用。 如果有多个消费者,那么这个消费者就是潜在的收件人; 解析函数将选择满意的顺序。 (2)任何性能差异取决于实施。 不要问我们 - 你有最重要的权力在你面前:你的电脑。 使用您选择的测试场景和timeit工具。 (1) No, the consumer is not holding a lock; it's merely blocked until the request is satisfied, but the queue is sti ...
  • 我想通了......毕竟答案在文档中: https://docs.python.org/3/library/multiprocessing.html#pipes-and-queues 尤其是: 它们的不同之处在于Queue缺少在Python 2.5的queue.Queue类中引入的task_done()和join()方法。 在我的情况下,解决方案似乎是将此添加到关闭代码: self.imgbuffer.cancel_join_thread() I figured it out... the answer ...
  • 虽然其他人不可能运行此代码(它不是自包含的),但是你所展示的内容没有明显的问题。 所以问题在于你没有展示的东西 - 可能在代码创建和使用TaskExecutor实例。 当我插入缺少的部分时,我凭空捏造,这段代码运行良好。 所以你需要展示的不仅仅是这个。 如何更换: logger.debug("try to get queued task") 同 logger.debug("try to get queued task from queue %s", self.taskInfos) ? 那么至少我们可以看 ...
  • 正如你的建议,我不确定我会考虑信号量并锁定“更强大的方法”。 队列通常是高阶抽象。 换句话说,您可以使用信号量和锁来构建线程安全的队列。 你在哪里使用取决于你的应用程序。 队列适用于在线程和进程之间传递“工作”,而信号量/锁定对于保护关键部分或共享资源很有用,因此一次只能访问一个线程。 I'm not sure I'd consider semaphores and locks "more powerful methods", as you suggest. Queues are generally a h ...
  • 我能解释那个吗? 您会观察到这种行为,因为您始终在修改同一个对象 让我们放置队列/线程,并使用一些prints运行简化的代码,以了解正在发生的事情 t = {} l = [] for i in range(3): t['a'] = i l.append(t) print(l) t['a'] = 20 print(l) print(map(id, l)) [{'a': 2}, {'a': 2}, {'a': 2}] [{'a': 20}, {'a': 20}, {'a': 20}] # th ...
  • 您的代码中存在竞争条件。 想象一下,在Queue只剩下一个项目,而你只使用两个线程而不是8.然后发生以下事件序列: 线程A调用q.empty来检查它是否为空。 由于队列中有一个项目结果为False ,因此执行循环体。 在线程A调用q.get之前,有一个上下文切换,线程B可以运行。 线程B调用q.empty ,队列中仍有一个项目因此结果为False并执行循环体。 线程B在没有参数的情况下调用q.get ,它立即返回队列中的最后一项。 然后线程B处理该项并退出,因为q.empty返回True 。 线程A开始运行 ...
  • 我建议用collections.deque替换Queue.Queue使用。 Queue类旨在用于线程之间的同步通信,因此在用作常规数据结构时会产生一些不必要的开销。 collections.deque是一个更快的选择。 (名称“deque”的发音为“deck”,意思是“双端队列”。) deque类的确有与Queue类型不同的API,但它们之间的转换应该很容易。 使用deque.append代替Queue.put和deque.popleft代替q.get() (或者appendleft和pop ,如果你想转向 ...
  • 我想你想从多处理模块中使用Queue ,然后以这种方式导入 - from multiprocessing import Queue 如果要使用队列数据结构,则使用小写queue 。 import queue I guess you want to use Queue from multiprocessing module, then import this way - from multiprocessing import Queue If you want to use the queue data ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)