iOS - Concurrency Programming Guide (iOS并行编程指南)

程序员思维日志:用Programming.log沉淀可复用的技术认知 编程日志(Programming.log)是一种面向工程师认知演化的轻量级知识管理范式,其核心在于以时间戳为索引、以问题驱动为线索、以可验证代码为证据,实现思考过程的低摩擦记录与高复用回溯。它区别于传统技术博客,不追求传播性,而专注解决‘为什么这样选’‘bug为何难定位’‘概念何时真正理解’三类不可替代的认知资产沉淀。通过纯文本+静态站点的技术栈,天然支持离线编辑、全文搜索与Git版本化演进,成为程序员对抗信息熵增、构建个人技术复利系统的底层基础设施。本文详解其设计哲学、内容结构与工程落地实践。 阅读详情


当代码中需要异步执行一些工作的时候,需要用到异步编程的技术。在iOS下进行并行编程的方法有四种:

1. Operation Queues:把要执行的工作打包成一个Objective-C对象,并且该对象的class类型必须继承自NSOperation。

2. Dispatch Queues:把要执行的工作打包成一个函数或一个block对象。有两种该类型的queue:serial dispatch queue,concurrent dispatch queue。区别在于:serial dispatch queue采取FIFO的原则,执行完一个task之后,再去从queue里取出另外一个task执行,也就是说第二个task开始执行时,第一个task肯定都执行完了。而concurrent dispatch queue虽然也是采取FIFO的原则,但后面的task不会等前面的task执行完后再执行,而是真的并行。

3. Dispatch Sources:异步的处理来自系统的事件。

4. 线程:用线程相关的函数创建一个新的线程,在新线程里完成需要异步进行的工作。这是最原始的方法,在iOS上不鼓励。


在平常的工作中,最常用的是 Dispatch Queues ,其他三种几乎不用。下面就重点介绍下 Dispatch Queues 。


Dispatch Queues的类型


类型

描述

Serial

又被称为private dispatch queues,会在一个不同的线程按照FIFO的顺序执行task。可通过dispatch_queue_create创建任意数量的

serial queue,注意的是各个queue之间是完全并行的,但每一个queue内的task是按照顺序一个一个执行的。

Concurrent

又被称为global dispatch queue,task依然会按照FIFO的顺序取出执行,但下一个task不会等待上一个task完成才去执行,task之间

是完全并行的。这些task实际上会被扔到多个不同的线程里并行执行。系统预置了4种global dispatch queue,这4种queue的区别在

于其优先级的不同。另外,因为这些预置的queue是global的,所以不用考虑retain、release的问题。

Main dispatch queue

是一个global的serial queue,只不过与main thread线程绑定了,可以在application的main thread里按照FIFO的顺序执行task。可

以通过dispatch_get_main_queue获取该queue。

相关API

1. dispatch_get_current_queue

这个接口一般用于debug或测试:在block内部调用该接口,可以得到该block被投递到哪个queue里了;在block外部调用该接口,可得到当前默认的concurrent queue。

2. dispatch_get_main_queue

得到当前与main thread绑定的 global Serial dispatch queue。

3. dispatch_get_global_queue

得到当前系统预置的 global Concurrent dispatch queue。

4. dispatch_queue_create

创建一个新的 Serial dispatch queue。


dispatch queue的内存管理

1. 对于自己创建的(private dispatch queue),需要通过 dispatch_retain 和 dispatch_release 管理queue对象的生存期。

2. 对于 global dispatch queue,系统会自动处理,不用程序员管了。


为queue绑定自定义数据(context data)

可以通过 dispatch_set_context and dispatch_get_context 为所有类型的queue绑定自定义的数据,称之为context,该context数据的 allocate 和 deallocate 由程序员负责。


为Serial dispatch queue设置一个clean up的函数

创建一个Serial dispatch queue之后,可以为该queue设置一个clean up函数,该函数会在queue被 deallocate 之前调用,主要用于释放context data。如果没有为该queue绑定context data,也即context指针为NULL,那么该clean up函数将不会被调用。

示例: Installing a queue clean up function

void myFinalizerFunction(void *context)
{
    MyDataContext* theData = (MyDataContext*)context;
 
    // Clean up the contents of the structure
    myCleanUpDataContextFunction(theData);
 
    // Now release the structure itself.
    free(theData);
}
 
dispatch_queue_t createMyQueue()
{
    MyDataContext*  data = (MyDataContext*) malloc(sizeof(MyDataContext));
    myInitializeDataContextFunction(data);
 
    // Create the queue and set the context data.
    dispatch_queue_t serialQueue = dispatch_queue_create("com.example.CriticalTaskQueue", NULL);
    if (serialQueue)
    {
        dispatch_set_context(serialQueue, data);
        dispatch_set_finalizer_f(serialQueue, &myFinalizerFunction);
    }
 
    return serialQueue;
}


向Queue中添加task

有两种方式:同步(synchronously)或 异步(asynchronously)。

同步API: dispatch_sync 和 dispatch_sync_f

异步API:dispatch_async 和 dispatch_async_f

在实际中,使用同步的方式很少,比如为了避免race condition等。

示例:dispatching tasks asynchronously and synchronously:

dispatch_queue_t myCustomQueue;
myCustomQueue = dispatch_queue_create("com.example.MyCustomQueue", NULL);
 
dispatch_async(myCustomQueue, ^{
    printf("Do some work here.\n");
});
 
printf("The first block may or may not have run.\n");
 
dispatch_sync(myCustomQueue, ^{
    printf("Do some more work here.\n");
});
printf("Both blocks have completed.\n");


Performing a Completion Block When a Task Is Done

有时候我们希望知道被异步执行的task在什么时候完成,并且能将执行结果返回给我们,这时候就可以在task的末尾再一次通过 dispatch_async 将另一个block dispatch到指定的queue,并将task执行的结果返回给该queue。

示例:Executing a completion callback after a task

void average_async(int *data, size_t len,
   dispatch_queue_t queue, void (^block)(int))
{
   // Retain the queue provided by the user to make
   // sure it does not disappear before the completion
   // block can be called.
   dispatch_retain(queue);
 
   // Do the work on the default concurrent queue and then
   // call the user-provided block with the results.
   dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
      int avg = average(data, len);
      dispatch_async(queue, ^{ block(avg);});
 
      // Release the user-provided queue when done
      dispatch_release(queue);
   });
}


Suspending and Resuming Queues

dispatch_suspend:让queue暂停执行blocks,并且将 suspension reference count 加 一

dispatch_resume:恢复执行blocks,并且将 suspension reference count 减 一

只要 suspension reference count 的值大于0,那该queue就是 suspended 状态,因此要平衡好 dispatch_suspend 和 dispatch_resume 的调用次数。


Waiting on Groups of Queued Tasks

如果要阻塞一个线程,以便等待一个或多个task完成,就可以采用 Dispatch groups 技术。相关API为:dispatch_group_async 和 dispatch_group_wait。

示例:Waiting on asynchronous tasks

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_group_t group = dispatch_group_create();
 
// Add a task to the group
dispatch_group_async(group, queue, ^{
   // Some asynchronous work
});
 
// Do some other work while the tasks execute.
 
// When you cannot make any more forward progress,
// wait on the group to block the current thread.
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
 
// Release the group when it is no longer needed.
dispatch_release(group);


ConcurrencyProgramming Guide 苹果官方文档:文档介绍了Mac OS X上的线程包并提供了这个线程包的使用方法。这个文档也描述了在你的应用中支持线程和多线程代码同步的相关技术。 立即下载

相关推荐

Mastering macOS Programming

Mastering macOS Programming by Stuart Grimshaw English | 31 May 2017 | ASIN: B01LWACIKS | 626 Pages | AZW3 | 6.43 MB Key Features Learn to harness the power of macOS with the elegance of the Swift programming language Become highly competent in building apps on the macOS platform Get the most in-depth guide with a hands-on approach on the latest version of macOS Book Description macOS continues to lead the way in desktop operating systems, with its tight integration across the Apple ecosystem of platforms and devices. With this book, you will get an in-depth knowledge of working on macOS, enabling you to unleash the full potential of the latest version using Swift 3 to build applications. This book will help you broaden your horizons by taking your programming skills to next level. The initial chapters will show you all about the environment that surrounds a developer at the start of a project. It introduces you to the new features that Swift 3 and Xcode 8 offers and also covers the common design patterns that you need to know for planning anything more than trivial projects. You will then learn the advanced Swift programming concepts, including memory management, generics, protocol orientated and functional programming and with this knowledge you will be able to tackle the next several chapters that deal with Apple's own Cocoa frameworks. It also covers AppKit, Foundation, and Core Data in detail which is a part of the Cocoa umbrella framework. The rest of the book will cover the challenges posed by asynchronous programming, error handling, debugging, and many other areas that are an indispensable part of producing software in a professional environment. By the end of this book, you will be well acquainted with Swift, Cocoa, and AppKit, as well as a plethora of other essential tools, and you will be ready to tackle much more complex and advanced software projects. What You Will Learn Combine beautiful design with robust code for the very best user experienc

Concurrency Programming Guide

Introduction并发表示多个事情在同一时间发生。伴随着多核CPU的增多和每个处理器的核的数量的上升,软件开发需要新的途径来利用这些优势。虽然像OS X and iOS这些操作系统有能力并发运行多个程序,大部分运行在后台的程序只需要少量连续的处理时间。是当前前台程序捕捉用户事件让处理器保持忙碌。如果一个程序有很多的工作但全让一个核来做,其他的处理资源就被浪费掉了。在以前,在一个app中引进并发

奔向火星的博客 502

Concurrent Programming in Mac OS X and iOS 无水印pdf

Concurrent Programming in Mac OS X and iOS 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

Concurrency Programming Guide 并发设计指引(一)

Introduction Concurrency is the notion of multiple things happening at the same time. With the proliferation of multicore CPUs and the realization that the number of cores in each processor will on

静水流深~专栏 1570

cst-python联合仿真的问题解决

cst与python联合仿真出现无法调用CST的问题解决

ayihu_的博客 2370

Windows 11 IoT企业版LTSC 24H2/25H2中文版安装指南(含OEM激活教程)

本文详细介绍了Windows 11 IoT企业版LTSC 24H2/25H2中文版的安装与OEM激活全流程。从系统镜像准备、硬件兼容性检查到自动化安装配置,再到OEM激活方案(包括SLIC注入和数字许可证激活),为工业自动化、数字标牌等物联网设备提供稳定可靠的系统部署指南。

weixin_29198045的博客 8813

Concurrency Programming Guide 并发设计指引(四)

分解出可执行的工作单元 以你对应用程序的任务的理解,你应该已经能够确定你的代码可能适合使用并发的地方。如果改变任务中的一个或多个步骤的顺序改变了输出结果,你可能需要继续串行执行这些步骤。如果改变顺序后没有对输出的影响造成影响,你应该考虑并行执行这些步骤。在这两种情况下,你定义可执行的工作单元,工作单元表示要执行的一个或多个步骤

静水流深~专栏 1313

AI应用架构师:引领半导体良率AI预测的变革浪潮

在半导体行业这个技术密集、资本密集且竞争异常激烈的领域,良率是决定企业盈利能力的关键指标。每提升1%的良率可能意味着数亿美元的利润增长。然而,随着制程节点不断缩小至3nm、2nm甚至更先进水平,传统的良率管理方法已难以应对日益复杂的制造流程和指数级增长的数据量。本文将深入探讨AI应用架构师如何成为这场变革的核心驱动力,通过设计和实施先进的AI预测系统,将半导体良率预测从传统的"事后分析"转变为"事前预测"和"实时优化"。

AI大模型应用之禅 403

Concurrency Programming Guide 并发设计指引(二)

以下翻译是本人通过谷歌工具进行翻译,并进行修正后的结果,希望能对大家有所帮助。如果您发现翻译的不正确不合适的地方,希望您能够发表评论指正,谢谢。转载请注明出处。 Concurrency and Application Design 并发和程序设计 In the early days of computing, the maximum amount of work per unit

静水流深~专栏 1415

ROS 2在自动驾驶中的应用:感知节点开发

ROS 2在自动驾驶中的应用:感知节点开发 ,人工智能,计算机视觉,大模型,AI,本文围绕ROS 2在自动驾驶感知节点开发展开,介绍了ROS 2基础、感知节点开发流程,包括环境搭建、代码编写等,还阐述了常用传感器感知节点开发、多传感器融合,以及测试调试、性能优化、部署集成等内容,分析了开发面临的挑战与未来趋势,为相关开发提供了全面指导,涉及简单代码示例和概念解释。

不踩坑,不知道坑有多深;不总结,踩过的坑白踩。 14万+

利用 SAP Joule 提升 ABAP 开发效率的前提条件与限制全解析

综上,想要在 ABAP Development Tools 中顺利使用 SAP Joule,既要准备好 BTP、IAS、ABAP 系统与 ADT 的版本与信任链,也要理解许可证、配额、语法范围等限制。只有在这些前提全部满足后,Joule 才能真正发挥生成式 AI 的价值,帮助 ABAP 开发者从繁琐模板中解放出来,把注意力投入在业务创新与 Clean Core 改造之上。未来 SAP 还将扩展中文语境、自动修复建议以及跨系统智能代理等功能,值得持续关注。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 661

iOS开发之-Concurrency Programming Guide

Terminology  The term thread is used to refer to a separate path of execution for code. The term process is used to refer to a running executable, which can encompass multiple threads.The term task

198

7、树莓派故障排查全攻略

本文详细介绍了树莓派在使用过程中常见的各类故障及其排查方法。内容涵盖键盘鼠标诊断、电源诊断、显示诊断、启动诊断、网络诊断以及紧急内核的使用,提供了具体的解决方法和实用建议。同时,文章总结了故障排查流程、常见故障及解决方法的汇总,并给出了注意事项和操作建议,帮助用户高效解决树莓派使用过程中的问题,确保其稳定运行。

cream的博客 323

学习iOS 编程的一些建议

小编在网上找了一下资料,总结了一些经验,如何从一个iOS毛头小子到现在的高级工程师,先跟大家分享一下一些好的资料。1首先推荐几本教材http://www.bignerdranch.com/we-write/objective-c-programming.htmlhttp://www.bignerdranch.com/we-write/ios-programming.html(这两本书都有中文版的)...

qq_41597968的博客 601

固定效应模型-以stata为工具

固定效应模型(Fixed Effects Model)是一种面板数据分析方法,通过引入个体固定效应来控制个体间的异质性,并更准确地估计解释变量对因变量的影响。它在许多经济、社会科学和健康研究中被广泛应用。

侯小啾技术博客 2837

YOLOv8【第一章:基础入门篇·第1节】一文搞定,核心架构深度解析与环境配置!

🏆 本文收录于 《YOLOv8实战:从入门到深度优化》 专栏,该专栏专注于分享我在YOLOv8目标检测模型中的实战经验,涵盖从入门基础到深度优化的全方位解决方案。无论你是计算机视觉的新手,还是具有多年深度学习经验的专家,本专栏都将为你提供高效、可复现的技术方案,助你掌握YOLOv8的核心技术,提升目标检测性能,突破瓶颈,优化模型,并加速项目开发🚀!

**My Coding Family** 2101

Concurrency Programming Guide 并发设计指引(三)

以下翻译是本人通过谷歌工具进行翻译,并进行修正后的结果,希望能对大家有所帮助。如果您发现翻译的不正确不合适的地方,希望您能够发表评论指正,谢谢。转载请注明出处。 Dispatch Queues Dispatch queues are a C-based mechanism for executing custom tasks. A dispatch queue executes tasks

静水流深~专栏 1581

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

iOS开发之-Concurrency Programming Guide - Dispatch Queues

Dispatch Queues About Dispatch Queues 1. A task is simply some work that your application needs to perform. For example, you could define a task to perform some calculations, create or modify

519

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Concurrency Programming Guide 并发设计指引(五) Operation Queues

CocoaOperations是一个面向对象的方式来封装要异步执行工作。Operations被设计成结合操作队列(OperationQueue)使用,也可以自己单独使用。因为他们是基于Objective-C中,在OSX和iOS,Operations最常用于基于Cocoa的应用程序。 本章将告诉您如何定义和使用Operations。

静水流深~专栏 1304

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

iOS资料必看

更多iOS技术文章,请关注 博客: http://blog.sina.com.cn/s/blog_a841894b0102v0jc.html 微博: http://www.weibo.com/u/28228672751.1. 首先推荐几本教材:http://www.bignerdranch.com/we-write/objective-c-programming.html http://www

IOS_Mainstay的博客 580

iOS 并发编程(1)

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33909059的博客 75

GCD Operation 等线程知识点 在IOS Developer Library 中的位置

GCD OperationTopics -> Performance -> Concurrency Programming Guide 转载于:https://www.cnblogs.com/appleice/p/4392215.html

weixin_30619101的博客 75

顺丰科技iOS秋招客观题解析:内存管理、Runtime与多线程高频考点精讲

在iOS开发岗位的笔试与面试中,对Objective-C底层机制的理解程度往往决定了候选人能否从众多竞争者中脱颖而出。内存管理作为iOS开发的核心基石,涵盖了weak与copy修饰符的底层差异、block的捕获机制以及ARC下的循环引用问题;而Runtime则赋予Objective-C动态性,消息转发流程与KVO的isa-swizzling实现是区分“会用”和“懂原理”的分水岭。多线程场景下,GCD队列与死锁的关系、atomic的局限也是工程实践中常踩的坑。这些知识不仅支撑着App的稳定性与性能表现,更在物

weixin_34262482的博客 289

Go语言2026年TIOBE排名分析及技术前景

编程语言排名是衡量技术生态活跃度的重要指标,其中TIOBE指数通过搜索引擎数据、开发者社区活跃度等维度评估语言热度。Go语言作为Google开发的系统级语言,凭借其高效的并发模型(goroutine)和卓越的编译速度,在云计算和微服务架构领域建立了技术优势。随着云原生技术栈的普及,Go在Docker、Kubernetes等核心基础设施中的广泛应用证明了其工程价值。虽然2026年TIOBE排名显示Go语言有所下滑,但结合其成熟的工具链和稳定的企业采用率来看,这种波动更可能反映市场关注度的自然调整而非技术衰退。

weixin_34387468的博客 412
上一篇: iOS - id && Object Messaging 深入讲解
下一篇: iOS URL Loading System
object_c_key
博客等级 码龄11年 0粉丝 9原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值