zoukankan      html  css  js  c++  java
  • POSIX Threads & Cocoa Threads

    Protecting the Cocoa Frameworks

      For multithreaded applications, Cocoa frameworks use locks and other forms of internal synchronization to ensure they behave correctly. To prevent these locks from degrading performance in the single-threaded case, however, Cocoa does not create them until the application spawns its first new thread using the NSThread class. If you spawn threads using only POSIX thread routines, Cocoa does not receive the notifications it needs to know that your application is now multithreaded. When that happens, operations involving the Cocoa frameworks may destabilize or crash your application.

    To let Cocoa know that you intend to use multiple threads, all you have to do is spawn a single thread using the NSThread class and let that thread immediately exit. Your thread entry point need not do anything. Just the act of spawning a thread using NSThread is enough to ensure that the locks needed by the Cocoa frameworks are put in place.

    If you are not sure if Cocoa thinks your application is multithreaded or not, you can use the isMultiThreaded method of NSThread to check.

    保护Cocoa框架

      为了让Cocoa知道你将使用多线程,所有你需要做的就是用NSThread创建一个线程,然后让线程立即退出。这样就能让Cocoa框架知转换到多线程状态下。

      通过NSThread类的isMultiThreaded方法,可以查看当前Cocoa线程状态。

    Mixing POSIX and Cocoa Locks

      It is safe to use a mixture of POSIX and Cocoa locks inside the same application. Cocoa lock and condition objects are essentially just wrappers for POSIX mutexes and conditions. For a given lock, however, you must always use the same interface to create and manipulate that lock. In other words, you cannot use a Cocoa NSLock object to manipulate a mutex you created using thepthread_mutex_init function, and vice versa.

    混合POSIX和Cocoa锁

      Cocoa Lock只是POSIX Lock的封装,你不能用NSLock对象去操作用pthread_mutex_init函数产生的mutex。

  • 相关阅读:
    有关WCSF的几点整理
    应用Response.Write实现带有进度条的多文件上传
    使用Response.Write实现在页面的生命周期中前后台的交互
    多线程实现Thread.Start()与ThreadPool.QueueUserWorkItem两种方式对比
    LinQ to SQL 及 non-LinQ方式实现Group的Performance对比
    Object.assign()方法
    继承
    面对对象和原型链
    画布实现验证码
    日期的格式 字符串转日期
  • 原文地址:https://www.cnblogs.com/tekkaman/p/2203577.html
Copyright © 2011-2022 走看看