zoukankan      html  css  js  c++  java
  • Thread Costs

    https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html#//apple_ref/doc/uid/10000057i-CH15-SW7

    Threading has a real cost to your program (and the system) in terms of memory use and performance. Each thread requires the allocation of memory in both the kernel memory space and your program’s memory space. The core structures needed to manage your thread and coordinate its scheduling are stored in the kernel using wired memory. Your thread’s stack space and per-thread data is stored in your program’s memory space. Most of these structures are created and initialized when you first create the thread—a process that can be relatively expensive because of the required interactions with the kernel. 

    Table 2-1 quantifies the approximate costs associated with creating a new user-level thread in your application. Some of these costs are configurable, such as the amount of stack space allocated for secondary threads. The time cost for creating a thread is a rough approximation and should be used only for relative comparisons with each other. Thread creation times can vary greatly depending on processor load, the speed of the computer, and the amount of available system and program memory.

    Table 2-1  Thread creation costs

    Item

    Approximate cost

    Notes

    Kernel data structures

    Approximately 1 KB

    This memory is used to store the thread data structures and attributes, much of which is allocated as wired memory and therefore cannot be paged to disk.

    Stack space

    512 KB (secondary threads)

    8 MB (OS X main thread)

    1 MB (iOS main thread)

    The minimum allowed stack size for secondary threads is 16 KB and the stack size must be a multiple of 4 KB. The space for this memory is set aside in your process space at thread creation time, but the actual pages associated with that memory are not created until they are needed. 

    Creation time

    Approximately 90 microseconds

    This value reflects the time between the initial call to create the thread and the time at which the thread’s entry point routine began executing. The figures were determined by analyzing the mean and median values generated during thread creation on an Intel-based iMac with a 2 GHz Core Duo processor and 1 GB of RAM running OS X v10.5.

    Note: Because of their underlying kernel support, operation objects can often create threads more quickly. Rather than creating threads from scratch every time, they use pools of threads already residing in the kernel to save on allocation time. For more information about using operation objects, see Concurrency Programming Guide

    Another cost to consider when writing threaded code is the production costs. Designing a threaded application can sometimes require fundamental changes to the way you organize your application’s data structures. Making those changes might be necessary to avoid the use of synchronization, which can itself impose a tremendous performance penalty on poorly designed applications. Designing those data structures, and debugging problems in threaded code, can increase the time it takes to develop a threaded application. Avoiding those costs can create bigger problems at runtime, however, if your threads spend too much time waiting on locks or doing nothing.

  • 相关阅读:
    机器学习:不平衡信息有序平均加权最近邻算法IFROWANN
    项目代码管理工具Git的总结
    jquery的返回顶端的功能实现
    web项目中登陆超时的功能实现(基于C#)
    存储过程:项目中使用存储过程的一个实例
    Vbox中unbuntu15.10与win10共享文件 及开启复制粘贴功能
    网站开发常用Sql语句
    维护基于ASP.NET的网站的学习-SqlCommand类介绍及存储过程
    本地向服务器上传文件的方式-FTP工具上传
    本地向服务器上传文件的方式-本地资源映射到服务器
  • 原文地址:https://www.cnblogs.com/feng9exe/p/6757450.html
Copyright © 2011-2022 走看看