WO2018165952A1 - iOS线程恢复的方法及装置 - Google Patents

iOS线程恢复的方法及装置 Download PDF

Info

Publication number
WO2018165952A1
WO2018165952A1 PCT/CN2017/076975 CN2017076975W WO2018165952A1 WO 2018165952 A1 WO2018165952 A1 WO 2018165952A1 CN 2017076975 W CN2017076975 W CN 2017076975W WO 2018165952 A1 WO2018165952 A1 WO 2018165952A1
Authority
WO
WIPO (PCT)
Prior art keywords
thread
blocking
specified
recovery
time
Prior art date
Application number
PCT/CN2017/076975
Other languages
English (en)
French (fr)
Inventor
吴思蒙
Original Assignee
深圳大趋智能科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳大趋智能科技有限公司 filed Critical 深圳大趋智能科技有限公司
Priority to PCT/CN2017/076975 priority Critical patent/WO2018165952A1/zh
Priority to CN201780001577.6A priority patent/CN107690625B/zh
Publication of WO2018165952A1 publication Critical patent/WO2018165952A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1415Saving, restoring, recovering or retrying at system level
    • G06F11/1438Restarting or rejuvenating

Definitions

  • the present invention relates to the field of thread control, and in particular, to a method and apparatus for iOS thread recovery.
  • a thread is a single sequential control process in a program.
  • a relatively independent, schedulable execution unit in a process is the basic unit for system independent scheduling and dispatching of CPUs.
  • the thread has three basic states: ready, blocked, and running.
  • the ready state means that the thread has all the conditions for running, and can be logically run, waiting for the processor;
  • the running state refers to the thread occupying the processor is running;
  • Blocking state means that a thread is waiting for an event (such as a semaphore) that is logically unexecutable.
  • iOS supports a variety of (NSThread, NSOperation, GCD) threading methods, which can meet the multi-threading requirements in the program burst. There are many ways to block the thread, but there is no better recovery method. In the case of thread blocking, you can easily restore the thread as needed to continue the remaining tasks.
  • the NSThread method is used to block threads, and the code is simple, but not flexible enough, and the point of thread recovery cannot be controlled at will.
  • This method needs to limit the blocking time of the thread.
  • the specified thread in the day is blocked but not recoverable.
  • the thread will be automatically restored only after the specified time, that is, the thread recovery point cannot be precisely controlled, but In many programs, you need to restore threads at the specified point.
  • NSOperation and GCD methods can both block threads and restore threads as needed.
  • NSOperation and GCD control threads in units of queues and cannot be specific to a particular thread. For example, in a parallel queue, we will block the threads in the entire queue, instead of specifying a specific thread blocking, that is, we cannot accurately select the specific thread blocking.
  • the main object of the present invention is to provide a method and apparatus for iOS thread recovery, which can accurately implement thread blocking and recovery through conditional locks.
  • the present invention provides a method for iOS thread recovery, including,
  • the specified thread is controlled to enter the thread recovery; otherwise, the loop determines whether the specified thread needs to continue blocking.
  • the loop determines whether the specified thread needs to continue the blocking step, including,
  • the specified thread is controlled to enter the thread recovery. Otherwise, the loop determines whether the blocking time of the specified thread is less than the preset time.
  • the determining, before the specified thread needs to continue the blocking step includes
  • a class is created, the class includes an NSCondition conditional lock and a property Bool, and the NSCondition conditional lock is used to control thread blocking and recovery, and the attribute Bool is used to determine whether the thread needs to be blocked.
  • the method includes: [0019] when the specified thread enters the thread blocking, setting the specified thread target blocking time to be the preset time .
  • the present invention also proposes an apparatus for iOS thread recovery, including
  • a blocking determining unit configured to determine whether the specified thread needs to continue blocking
  • the first execution unit is configured to: if the specified thread does not need to continue blocking, control the specified thread to enter the thread recovery; otherwise, the loop determines whether the specified thread needs to continue blocking.
  • the method further includes: a daytime determining unit, configured to determine whether a blocking time of the specified thread is less than a preset time;
  • the second execution unit is configured to control the specified thread to enter the thread recovery if the blocking time is greater than or equal to the preset time, otherwise, the loop determines whether the blocking time of the specified thread is less than the preset time, and the loop judgment designates Whether the thread needs to continue to block.
  • the method further includes: a new unit, configured to establish a class, where the class includes an attribute NSCondition conditional lock and an attribute Bool, where the NSCondition conditional lock is used to control thread blocking and recovery, and the attribute Bool is used. Determine if the thread needs to block.
  • the device further includes a time setting unit, configured to set a specified thread target blocking time to be a preset time after the specified thread enters the thread blocking.
  • the beneficial effects of the present invention are: determining whether the specified thread continues to block through the attribute Bool, and realizing recovery of the specified thread through the NSCondition conditional lock, which is convenient to use and simple to use; the peer can both block the thread and can follow ⁇ Thread recovery; can block or restore a certain thread, instead of blocking or recovering for a queue, avoiding the impact on other unrelated threads, and being able to recover threads later.
  • FIG. 1 is a schematic flowchart of a method for restoring an iOS thread according to an embodiment of the present invention
  • FIG. 2 is a schematic flowchart of a method for restoring an iOS thread according to another embodiment of the present invention
  • FIG. 3 is a structural block diagram of an apparatus for iOS thread recovery according to an embodiment of the present invention.
  • first”, “second” and the like in the present invention are used for descriptive purposes only, and are not to be construed as indicating or implying their relative importance or implicitly indicating the number of indicated technical features. .
  • features defining “first” and “second” may include at least one of the features, either explicitly or implicitly.
  • the technical solutions between the various embodiments may be combined with each other, but must be able to be On the basis of implementation, when the combination of technical solutions is contradictory or impossible to achieve, it should be considered that the combination of such technical solutions does not exist and is not within the scope of protection required by the present invention.
  • Conditional lock When a thread acquires a lock object, but because some conditions are not met, it needs to wait on this condition, until the condition is satisfied, it can continue to execute, and the conditional lock is needed; Blocking on a condition, when other threads find that the condition has changed, the conditional lock can be used to wake up the thread blocking the condition.
  • iOS is a mobile operating system that is issued by Apple. Apple first announced the system at the Ma cworld conference on January 9, 2007, originally designed for the iPhone, and later applied to iPod touch iPad and Apple TV, iOS and Apple's Mac OS X operating system. Similarly, it is a Unix-like commercial operating system.
  • a method for iOS thread recovery includes
  • the NSCondition conditional lock is used to add a lock to the thread.
  • the attribute Bool determines that the thread does not need to continue blocking
  • the specified thread is controlled so that the thread is in a ready state.
  • the beneficial effects of the present invention are: determining whether the specified thread continues to block through the attribute Bool, and realizing recovery of the specified thread through the NSCondition conditional lock, which is convenient to use and simple to use; the peer can both block the thread and can follow ⁇ Thread recovery; can block or restore a certain thread, instead of blocking or recovering for a queue, avoiding the impact on other unrelated threads, and being able to recover threads later.
  • FIG. 2 an embodiment of the present invention is provided, a method for iOS thread recovery, including
  • S21 Determine whether the specified thread needs to continue to block, and determine whether the blocking time of the specified thread is less than the preset time.
  • step S21 is performed until the condition of step S22 is satisfied.
  • step S21 there are two judging steps that do not interfere with each other, including:
  • S212 Determine whether the blocking time of the specified thread is less than a preset time.
  • step S211 and step S212 are simultaneously determined, and the determination results do not interfere with each other. Therefore, the determination result of step S211/the result of step S212 has the following four possibilities: Yes/Yes, Yes/No , No / No, No / Yes.
  • the judgment result is "yes/yes”
  • the specified thread continues to block and cannot be restored;
  • the judgment result is "yes/no, no/no, no/yes”, that is, if there is any, That is, after one or both of the two cases of "the specified thread does not need to continue blocking" or "the specified thread's blocking time is greater than or equal to the preset time" appear, the specified thread enters the thread recovery. It is possible to accurately achieve the recovery of a specified thread in a specific day.
  • step S22 when at least one of the two determination results is negative, that is, "determination of the specified thread does not need to continue blocking" or "the specified thread's blocking time is greater than or equal to the preset time", the control designation The thread is restored, and the specified thread can only be restored after the default is run.
  • step S20 is included: establishing a class, the class includes an NSCondition conditional lock and an attribute Bool, the NSCondition conditional lock is used to control thread blocking and recovery, and the attribute Bool is used to determine the line. Whether the process needs to be blocked.
  • the conditional lock acquires the lock object in the specified thread, but because some conditions are not met, it is necessary to wait on this condition, until the condition is satisfied, and then can continue to execute, which is needed, and is used in this embodiment.
  • the NSCondition conditional lock With the NSCondition conditional lock, thread recovery can be performed after one of the two conditions "The specified thread does not need to continue blocking" or "The specified thread's blocking time is greater than or equal to the default time".
  • step S211 setting the specified thread target blocking time to be preset after the specified thread enters the thread blocking time In the daytime.
  • thread blocking and recovery are two consecutive actions, and a thread is restored after the thread is blocked.
  • the Bluetooth data return needs to be timed, so before receiving the return data, the corresponding thread waits for the thread to block, and then calls the judgment loop to ensure that the corresponding thread continues to block until the data is returned and the decision is successfully sent. The corresponding thread is restored by the NSCondition conditional lock.
  • the iOS thread recovery method of the present invention determines whether the specified thread continues to block through the attribute Bool, and realizes the recovery of the specified thread through the NSCondition conditional lock, which is convenient to use and simple to use; the same can be blocked by the thread. Can be recovered with the thread; can block or restore a certain thread, instead of blocking or recovering for a queue, avoiding the impact on other unrelated threads, and being able to recover the thread later.
  • an embodiment of an iOS thread recovery apparatus includes:
  • the blocking determining unit 10 is configured to determine whether the specified thread needs to continue blocking.
  • the first execution unit 50 is configured to control the specified thread to enter the thread recovery if the blocking does not need to be continued, otherwise , looping to determine whether the specified thread needs to continue blocking, and blocking the determining unit to connect with the inter-day judging unit;
  • the inter-day judging unit 20 is configured to determine whether the blocking time of the specified thread is less than the preset time.
  • the second executing unit 60 is configured to control the specified thread to enter the thread recovery if the blocking time is greater than or equal to the preset time, otherwise, the loop determines whether the blocking time of the specified thread is less than the preset time, and the loop determines Specifies whether the thread needs to continue blocking;
  • the iOS thread recovery device further includes a new unit 30, the new unit is used to establish a class, the class includes an NSCondition conditional lock and an attribute Bool, the NSCondition conditional lock is used to control thread blocking and recovery, and the attribute Bool is used to determine whether the thread is used. Need to block.
  • the class includes the target blocking time of the specified thread. After the specified thread is blocked, it begins to judge the relationship between the actual blocking time and the preset time. When the actual blocking time is greater than or equal to the preset time, or the attribute Bool determines the pair. After the specified thread is restored, the specified thread is controlled for recovery.
  • the device for iOS thread recovery further includes a time setting unit, configured to set a specified thread target blocking time to be a preset time after the specified thread enters the thread blocking.
  • a time setting unit configured to set a specified thread target blocking time to be a preset time after the specified thread enters the thread blocking.
  • the blocking determination unit 10 and the inter-day determination unit 20 perform the same determination, and the determination results do not interfere with each other. Therefore, the determination results of the blocking determination unit 10 and the inter-day determination unit 20 have the following four types. Yu is / Yes, Yes / No, No / No, No / Yes.
  • the judgment result is "yes/yes”
  • the specified thread continues to block and cannot be restored;
  • the judgment result is "yes/no, no/no, no/yes”, that is, if there is any, That is, after one or both of the two cases of "the specified thread does not need to continue blocking" or "the blocking time of the specified thread is greater than the preset time” appear, the specified thread enters the thread recovery. It is possible to accurately implement the recovery of a specified thread between specific times.
  • the NSC ondition conditional lock condition is satisfied, and the specified thread is controlled to resume, instead of only running through the preset time. The specified thread can then be restored.
  • the iOS thread recovery device of the present invention determines the blocking of the specified thread through the attribute Bool, and realizes the recovery of the specified thread through the N SCondition conditional lock, which is convenient to use and simple to use; the peer can both block the thread and can With the thread recovery; you can block or restore a certain thread, instead of blocking or recovering for a queue, avoiding the impact on other unrelated threads, and being able to recover the thread later.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Debugging And Monitoring (AREA)

Abstract

本发明揭示了一种iOS线程恢复的方法及装置,方法包括:判断指定线程是否需要继续阻塞;若不需要继续阻塞,控制指定线程进入线程恢复,否则,循环判断指定线程是否需要继续阻塞。可以阻塞或恢复某一个确定的线程,避免对于其他不相关线程的影响,并且能够在随时恢复线程,使用方便,简单易用。

Description

iOS线程恢复的方法及装置 技术领域
[0001] 本发明涉及到线程控制领域, 特别是涉及到一种 iOS线程恢复的方法及装置。
背景技术
[0002] 线程是程序中一个单一的顺序控制流程, 进程内一个相对独立的、 可调度的执 行单元, 是系统独立调度和分派 CPU的基本单位, 线程有就绪、 阻塞和运行三种 基本状态。
[0003] 就绪状态, 是指线程具备运行的所有条件, 逻辑上可以运行, 在等待处理机; [0004] 运行状态, 是指线程占有处理机正在运行;
[0005] 阻塞状态, 是指线程在等待一个事件 (如某个信号量) , 逻辑上不可执行。
[0006] iOS支持多种 (NSThread, NSOperation, GCD)线程方式, 能满足程序幵发中对 多线程的需求。 多种方式都能实现对线程的阻塞, 但是却没有比较好的恢复方 法, 无法在线程阻塞的情况下, 根据需要方便的恢复线程从而继续执行剩下的 任务。
[0007] 具体的, 使用 NSThread方式使线程阻塞, 代码简单, 但是不够灵活, 线程恢复 的吋间点无法随意控制。 这种方式需要限定线程的阻塞吋间, 在吋间内指定的 线程阻塞但不可恢复, 只有到了规定的吋间后线程才会自动的恢复, 也就是线 程恢复的吋间点无法精准控制, 但是在很多的程序中, 需要在指定的吋间点恢 复线程。
[0008] 另外, 使用 NSOperation和 GCD方式既能使线程阻塞也能根据需要使线程恢复 。 但是, NSOperation和 GCD是以队列为单位来控制线程的, 不能够具体到某一 个线程。 比如在并行队列中我们会对整个队列中的线程都进行阻塞, 而不能够 指定具体的某一个线程阻塞, 也就是无法精准选择具体的线程阻塞。
技术问题
[0009] 本发明的主要目的为提供一种 iOS线程恢复的方法及装置, 通过条件锁来精准 的实现线程的阻塞和恢复。 问题的解决方案
技术解决方案
[0010] 本发明提出一种 iOS线程恢复的方法, 包括,
[0011] 判断指定线程是否需要继续阻塞;
[0012] 若不需要继续阻塞, 控制指定线程进入线程恢复, 否则, 循环判断指定线程是 否需要继续阻塞。
[0013] 进一步地, 所述循环判断指定线程是否需要继续阻塞步骤之前, 包括,
[0014] 判断指定线程的阻塞吋间是否小于预设吋间;
[0015] 若阻塞吋间大于或等于预设吋间, 控制指定线程进入线程恢复, 否则, 循环判 断指定线程的阻塞吋间是否小于预设吋间。
[0016] 进一步地, 所述判断指定线程是否需要继续阻塞步骤之前, 包括,
[0017] 建立一个类, 所述类中包括 NSCondition条件锁和属性 Bool, 所述 NSCondition 条件锁用于控制线程阻塞和恢复, 所述属性 Bool用于判断线程是否需要阻塞。
[0018] 进一步地, 所述判断指定线程的阻塞吋间是否小于预设吋间步骤之前, 包括, [0019] 在指定线程进入线程阻塞吋, 设定指定线程目标阻塞吋间为预设吋间。
[0020]
[0021] 本发明还提出了一种 iOS线程恢复的装置, 包括,
[0022] 阻塞判断单元, 用于判断指定线程是否需要继续阻塞;
[0023] 第一执行单元, 用于若所述指定线程不需要继续阻塞, 控制指定线程进入线程 恢复, 否则, 循环判断指定线程是否需要继续阻塞。
[0024] 进一步地, 还包括: 吋间判断单元, 用于判断指定线程的阻塞吋间是否小于预 设吋间;
[0025] 第二执行单元, 用于若阻塞吋间大于或等于预设吋间, 控制指定线程进入线程 恢复, 否则, 循环判断指定线程的阻塞吋间是否小于预设吋间, 且循环判断指 定线程是否需要继续阻塞。
[0026] 进一步地, 还包括: 新建单元, 用于建立一个类, 所述类中包括属性 NSCondit ion条件锁和属性 Bool, 所述 NSCondition条件锁用于控制线程阻塞和恢复, 所述 属性 Bool用于判断线程是否需要阻塞。 [0027] 进一步地, 还包括有吋间设定单元, 用于在指定线程进入线程阻塞吋, 设定指 定线程目标阻塞吋间为预设吋间。
发明的有益效果
有益效果
[0028] 本发明的有益效果是: 通过属性 Bool来判断指定线程是否继续阻塞, 以及通过 NSCondition条件锁来实现指定线程的恢复, 使用方便, 简单易用; 同吋可以既 能够线程阻塞也能够随吋线程恢复; 可以阻塞或恢复某一个确定的线程, 而不 是需要针对一个队列进行阻塞或恢复, 避免对于其他不相关线程的影响, 并且 能够在随吋恢复线程。
对附图的简要说明
附图说明
[0029] 图 1为本发明一实施例 iOS线程恢复的方法的流程示意图;
[0030] 图 2为本发明另一实施例 iOS线程恢复的方法的流程示意图;
[0031] 图 3为本发明一实施例 iOS线程恢复的装置的结构框图。
[0032]
[0033] 本发明目的的实现、 功能特点及优点将结合实施例, 参照附图做进一步说明。
实施该发明的最佳实施例
本发明的最佳实施方式
[0034] 应当理解, 此处所描述的具体实施例仅仅用以解释本发明, 并不用于限定本发 明。
[0035] 需要说明, 本发明实施例中所有方向性指示 (诸如上、 下、 左、 右、 前、 后… …) 仅用于解释在某一特定姿态。 各个部件之间的相对位置关系、 运动情况等 , 如果该特定姿态发生改变吋, 则该方向性指示也相应地随之改变。
[0036] 另外, 在本发明中涉及"第一"、 "第二"等的描述仅用于描述目的, 而不能理解 为指示或暗示其相对重要性或者隐含指明所指示的技术特征的数量。 由此, 限 定有"第一"、 "第二 "的特征可以明示或者隐含地包括至少一个该特征。 另外, 各 个实施例之间的技术方案可以相互结合, 但是必须是以本领域普通技术人员能 够实现为基础, 当技术方案的结合出现相互矛盾或无法实现吋应当认为这种技 术方案的结合不存在, 也不在本发明要求的保护范围之内。
[0037] 本技术领域技术人员可以理解, 除非特意声明, 这里使用的单数形式"一"、 " 一个"、 "所述 "和"该"也可包括复数形式。 应该进一步理解的是, 本实用新型的 说明书中使用的措辞"包括"是指存在所述特征、 整数、 步骤、 操作、 元件和 /或 组件, 但是并不排除存在或添加一个或多个其他特征、 整数、 步骤、 操作、 元 件、 组件和 /或它们的组。 这里使用的措辞"和 /或"包括一个或更多个相关联的列 出项的全部或任一单元和全部组合。
[0038] 本技术领域技术人员可以理解, 除非另外定义, 这里使用的所有术语 (包括技 术术语和科学术语) , 具有与本实用新型所属领域中的普通技术人员的一般理 解相同的意义。 还应该理解的是, 诸如通用字典中定义的那些术语, 应该被理 解为具有与现有技术的上下文中的意义一致的意义, 并且除非像这里一样被特 定定义, 否则不会用理想化或过于正式的含义来解释。
[0039] 条件锁: 当某线程获取了锁对象, 但因为某些条件没有满足, 需要在这个条件 上等待, 直到条件满足才能够往下继续执行吋, 就需要用到条件锁; 线程主动 在某条件上阻塞, 当其它线程发现条件发生变化吋, 就可以通过条件锁来唤醒 阻塞在此条件上的线程。
[0040] iOS, 是由苹果公司幵发的移动操作系统。 苹果公司最早于 2007年 1月 9日的 Ma cworld大会上公布这个系统, 最初是设计给 iPhone使用的, 后来陆续套用到 iPod touch iPad以及 Apple TV等产品上, iOS与苹果的 Mac OS X操作系统一样, 属于 类 Unix的商业操作系统。
[0041]
[0042] 参照图 1, 提出本发明一实施例, 一种 iOS线程恢复的方法, 包括,
[0043] S10、 判断指定线程是否需要继续阻塞。
[0044] Sl l、 若不需要继续阻塞, 控制指定线程进入线程恢复。
[0045] S12、 否则, 循环判断指定线程是否需要继续阻塞。
[0046] 通过 NSCondition条件锁为线程中加入锁, 当属性 Bool判定线程不需要继续阻塞 之后, 控制指定线程, 使得线程处于就绪状态会在运行状态。 [0047] 本发明的有益效果是: 通过属性 Bool来判断指定线程是否继续阻塞, 以及通过 NSCondition条件锁来实现指定线程的恢复, 使用方便, 简单易用; 同吋可以既 能够线程阻塞也能够随吋线程恢复; 可以阻塞或恢复某一个确定的线程, 而不 是需要针对一个队列进行阻塞或恢复, 避免对于其他不相关线程的影响, 并且 能够在随吋恢复线程。
[0048]
[0049] 参照图 2, 提出本发明一实施例, 一种 iOS线程恢复的方法, 包括,
[0050] S21、 判断指定线程是否需要继续阻塞, 同吋, 判断指定线程的阻塞吋间是否 小于预设吋间。
[0051] S22、 若判定指定线程不需要继续阻塞, 或, 该指定线程的阻塞吋间大于等于 预设吋间, 则控制指定线程进入线程恢复。
[0052] S23、 若判定指定线程需要继续阻塞, 且, 该指定线程的阻塞吋间小于预设吋 间, 则循环进行步骤 S21, 直到满足步骤 S22的情况。 对于步骤 S21, 包括有两个 互不干扰的判断步骤, 具体包括:
[0053] S211、 判断指定线程是否需要继续阻塞。
[0054] S212、 判断指定线程的阻塞吋间是否小于预设吋间。
[0055] 实际工作吋, 步骤 S211和步骤 S212同吋进行判断, 其判断结果互不干扰, 因此 , 步骤 S211判断结果 /步骤 S212的判断结果存在有以下 4种可能: 是 /是, 是 /否, 否 /否, 否 /是。 当判断结果为 "是 /是"的吋候, 指定线程继续阻塞, 不能恢复; 当 判断结果为"是 /否, 否 /否, 否 /是"这三种, 就是存在有否的情况下, 也就是出现 判断结果出现 "指定线程不需要继续阻塞 "或"指定线程的阻塞吋间大于或等于预 设吋间 "这两种情况之中的一种或两种之后, 指定线程进入线程恢复。 能够在具 体的吋间精准实现指定线程的恢复。
[0056] 对于步骤 S22, 当两个判断结果至少出现一个为否吋, 也就是出现"判定指定线 程不需要继续阻塞"或"指定线程的阻塞吋间大于等于预设吋间"吋, 控制指定的 线程进行恢复, 而不是只能在预设吋间跑完之后才可以恢复指定的线程。
[0057] 在步骤 S21之前, 包括步骤 S20: 建立一个类, 类中包括 NSCondition条件锁和 属性 Bool, NSCondition条件锁用于控制线程阻塞和恢复, 属性 Bool用于判断线 程是否需要阻塞。
[0058] 条件锁, 在指定线程获取了锁对象, 但因为某些条件没有满足, 需要在这个条 件上等待, 直到条件满足才能够往下继续执行吋, 就需要用到, 本实施例中使 用的是 NSCondition条件锁。 通过 NSCondition条件锁, 可以在 "指定线程不需要 继续阻塞"或"指定线程的阻塞吋间大于等于预设吋间"这两个条件之一得到满足 之后即可执行线程恢复。
[0059] 在步骤 "判断指定线程的阻塞吋间是否小于预设吋间"之前, 还包括有步骤 S211 , 步骤 S211 : 在指定线程进入线程阻塞吋, 设定指定线程目标阻塞吋间为预设 吋间。
[0060] 指定线程上有任务进入阻塞状态吋, 幵始为其计吋, 记为实际阻塞吋间, 通过 对比实际阻塞吋间与预设吋间之间的关系, 来确定进一步判断线程是否进行恢 复。
[0061] 具体的, 线程阻塞和恢复是连续的两个动作, 在线程阻塞之后会有线程恢复。
在本发明一具体应用实施例中, 手机程序和蓝牙设备进行信息交互吋, 有吋需 要手机设备向蓝牙设备发送数据, 并根据是否接收返回数据来判定数据是否发 送成功。 但蓝牙数据返回是需要吋间的, 所以在接收到返回数据之前, 对应的 线程等待也就是线程阻塞, 此吋调用判断循环来保证对应的线程持续阻塞, 直 到确认数据返回判定成功发送了数据, 再通过 NSCondition条件锁将对应线程恢 复。
[0062] 本发明的 iOS线程恢复的方法, 通过属性 Bool来判断指定线程是否继续阻塞, 以及通过 NSCondition条件锁来实现指定线程的恢复, 使用方便, 简单易用; 同 吋可以既能够线程阻塞也能够随吋线程恢复; 可以阻塞或恢复某一个确定的线 程, 而不是需要针对一个队列进行阻塞或恢复, 避免对于其他不相关线程的影 响, 并且能够在随吋恢复线程。
[0063]
[0064] 参考图 3, 本发明一实施例, 一种 iOS线程恢复的装置, 包括:
[0065] 阻塞判断单元 10, 用于判断指定线程是否需要继续阻塞。
[0066] 第一执行单元 50, 用于若不需要继续阻塞, 控制指定线程进入线程恢复, 否则 , 循环判断指定线程是否需要继续阻塞, 阻塞判断单元连接有吋间判断单元;
[0067] 吋间判断单元 20用于判断指定线程的阻塞吋间是否小于预设吋间,
[0068] 第二执行单元 60, 用于若阻塞吋间大于或等于预设吋间, 控制指定线程进入线 程恢复, 否则, 循环判断指定线程的阻塞吋间是否小于预设吋间, 且循环判断 指定线程是否需要继续阻塞;
[0069] iOS线程恢复的装置还包括新建单元 30, 新建单元用于建立一个类, 类中包括 NSCondition条件锁和属性 Bool, NSCondition条件锁用于控制线程阻塞和恢复, 属性 Bool用于判断线程是否需要阻塞。 类包括有指定线程的目标阻塞吋间, 在指 定线程阻塞之后, 幵始判断其实际阻塞吋间与预设吋间的关系, 当实际阻塞吋 间大于等于预设吋间, 或者属性 Bool判定对指定线程恢复之后, 控制指定线程进 行恢复。
[0070] iOS线程恢复的装置还包括吋间设定单元, 用于在指定线程进入线程阻塞吋, 设定指定线程目标阻塞吋间为预设吋间。 对于阻塞判断单元 10, 在使用吋, 需 要对指定线程进行阻塞, 通过判断指定线程是否需要对应的进行阻塞, 作为线 程进行阻塞的根据, 也就是当控制。 当判断后需要对指定线程进行阻塞, 控制 指定线程进入阻塞, 并加入阻塞循环条件, 使得指定线程在一定吋间段内一直 循环阻塞。
[0071] 实际工作吋, 阻塞判断单元 10和吋间判断单元 20同吋进行判断, 其判断结果互 不干扰, 因此, 阻塞判断单元 10和吋间判断单元 20的判断结果存在有以下 4种可 育 是 /是, 是 /否, 否 /否, 否 /是。 当判断结果为 "是 /是"的吋候, 指定线程继续 阻塞, 不能恢复; 当判断结果为 "是 /否, 否 /否, 否 /是"这三种, 就是存在有否的 情况下, 也就是出现判断结果出现"指定线程不需要继续阻塞"或"指定线程的阻 塞吋间大于预设吋间"这两种情况之中的一种或两种之后, 指定线程进入线程恢 复。 能够在具体的吋间精准实现指定线程的恢复。
[0072] 当阻塞判断单元 10和吋间判断单元 20的判断结果中至少出现一个为否吋, NSC ondition条件锁条件满足, 控制指定的线程进行恢复, 而不是只能在预设吋间跑 完之后才可以恢复指定的线程。
[0073] 指定线程上有任务进入阻塞状态吋, 幵始为其计吋, 记为实际阻塞吋间, 通过 对比实际阻塞吋间与预设吋间之间的关系, 来确定进一步判断线程是否进行恢 复。
[0074] 本发明 iOS线程恢复的装置, 通过属性 Bool来判断指定线程的阻塞, 以及通过 N SCondition条件锁来实现指定线程的恢复, 使用方便, 简单易用; 同吋可以既能 够线程阻塞也能够随吋线程恢复; 可以阻塞或恢复某一个确定的线程, 而不是 需要针对一个队列进行阻塞或恢复, 避免对于其他不相关线程的影响, 并且能 够在随吋恢复线程。
[0075]
[0076] 以上所述仅为本发明的优选实施例, 并非因此限制本发明的专利范围, 凡是利 用本发明说明书及附图内容所作的等效结构或等效流程变换, 或直接或间接运 用在其他相关的技术领域, 均同理包括在本发明的专利保护范围内。

Claims

权利要求书
一种 iOS线程恢复的方法, 其特征在于, 包括,
判断指定线程是否需要继续阻塞;
若不需要继续阻塞, 控制指定线程进入线程恢复, 否则, 循环判断指 定线程是否需要继续阻塞。
如权利要求 1所述的 iOS线程恢复的方法, 其特征在于, 所述循环判断 指定线程是否需要继续阻塞步骤之前, 包括,
判断指定线程的阻塞吋间是否小于预设吋间;
若阻塞吋间大于或等于预设吋间, 控制指定线程进入线程恢复, 否则
, 循环判断指定线程的阻塞吋间是否小于预设吋间。
如权利要求 1所述的 iOS线程恢复的方法, 其特征在于, 所述判断指定 线程是否需要继续阻塞步骤之前, 包括,
建立一个类, 所述类中包括 NSCondition条件锁和属性 Bool, 所述 NS Condition条件锁用于控制线程阻塞和恢复, 所述属性 Bool用于判断线 程是否需要阻塞。
如权利要求 2所述的 iOS线程恢复的方法, 其特征在于, 所述判断指 定线程的阻塞吋间是否小于预设吋间步骤之前, 包括,
在指定线程进入线程阻塞吋, 设定指定线程目标阻塞吋间为预设吋间 一种 iOS线程恢复的装置, 其特征在于, 包括,
阻塞判断单元, 用于判断指定线程是否需要继续阻塞;
第一执行单元, 用于若所述指定线程不需要继续阻塞, 控制指定线程 进入线程恢复, 否则, 循环判断指定线程是否需要继续阻塞。
如权利要求 5所述的 iOS线程恢复的装置, 其特征在于, 还包括: 吋间判断单元, 用于判断指定线程的阻塞吋间是否小于预设吋间; 第二执行单元, 用于若阻塞吋间大于或等于预设吋间, 控制指定线程 进入线程恢复, 否则, 循环判断指定线程的阻塞吋间是否小于预设吋 间, 且循环判断指定线程是否需要继续阻塞。 [权利要求 7] 如权利要求 5所述的 iOS线程恢复的装置, 其特征在于, 还包括: 新建单元, 用于建立一个类, 所述类中包括属性 NSCondition条件锁 和属性 Bool, 所述 NSCondition条件锁用于控制线程阻塞和恢复, 所 述属性 Bool用于判断线程是否需要阻塞。
[权利要求 8] 如权利要求 6所述的 iOS线程恢复的装置, 其特征在于, 还包括有吋间 设定单元, 用于在指定线程进入线程阻塞吋, 设定指定线程目标阻塞 吋间为预设吋间。
PCT/CN2017/076975 2017-03-16 2017-03-16 iOS线程恢复的方法及装置 WO2018165952A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
PCT/CN2017/076975 WO2018165952A1 (zh) 2017-03-16 2017-03-16 iOS线程恢复的方法及装置
CN201780001577.6A CN107690625B (zh) 2017-03-16 2017-03-16 iOS线程恢复的方法及装置

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2017/076975 WO2018165952A1 (zh) 2017-03-16 2017-03-16 iOS线程恢复的方法及装置

Publications (1)

Publication Number Publication Date
WO2018165952A1 true WO2018165952A1 (zh) 2018-09-20

Family

ID=61154853

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/076975 WO2018165952A1 (zh) 2017-03-16 2017-03-16 iOS线程恢复的方法及装置

Country Status (2)

Country Link
CN (1) CN107690625B (zh)
WO (1) WO2018165952A1 (zh)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1608246A (zh) * 2001-12-31 2005-04-20 英特尔公司 多线程处理器中对线程执行的挂起
CN103345422A (zh) * 2013-07-02 2013-10-09 厦门雅迅网络股份有限公司 一种基于Linux的多线程硬实时控制方法
US9207996B2 (en) * 2012-08-01 2015-12-08 Empire Technology Development Llc Active lock information maintenance and retrieval

Family Cites Families (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7823021B2 (en) * 2005-05-26 2010-10-26 United Parcel Service Of America, Inc. Software process monitor
US9256496B1 (en) * 2008-12-15 2016-02-09 Open Invention Network, Llc System and method for hybrid kernel—and user-space incremental and full checkpointing
CN101794244A (zh) * 2010-03-18 2010-08-04 上海乐毅信息科技有限公司 多线程看门狗监控方法
US8751861B2 (en) * 2012-02-08 2014-06-10 Lsi Corporation System and method for improved rebuild in RAID
CN103246552B (zh) * 2012-02-14 2018-03-09 腾讯科技(深圳)有限公司 防止线程出现阻塞的方法和装置
US9400677B2 (en) * 2013-01-02 2016-07-26 Apple Inc. Adaptive handling of priority inversions using transactions
US20150007050A1 (en) * 2013-07-01 2015-01-01 Gabriel Jakobson Method and system for processing and displaying email thread information
CN103345401A (zh) * 2013-07-30 2013-10-09 禹芙蓉 一种智能手机及其性能优化方法
CN103533609B (zh) * 2013-10-10 2016-07-06 成都达信通通讯设备有限公司 移动终端多apn网络通道并发网络系统及其创建方法
CN103617099B (zh) * 2013-12-10 2016-01-06 焦点科技股份有限公司 一种实时的用户文件内容审计方法及系统
CN104467187B (zh) * 2014-12-16 2016-04-27 重庆邮电大学 一种基于ios系统的智能电网远程监控系统
WO2016151398A1 (en) * 2015-03-23 2016-09-29 Societal Innovations Ipco Limited System and method for configuring a platform instance at runtime
CN104850460A (zh) * 2015-06-02 2015-08-19 上海斐讯数据通信技术有限公司 一种服务程序线程管理方法
CN105930208A (zh) * 2016-04-01 2016-09-07 广州华多网络科技有限公司 一种线程调度方法及线程调度装置

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1608246A (zh) * 2001-12-31 2005-04-20 英特尔公司 多线程处理器中对线程执行的挂起
US9207996B2 (en) * 2012-08-01 2015-12-08 Empire Technology Development Llc Active lock information maintenance and retrieval
CN103345422A (zh) * 2013-07-02 2013-10-09 厦门雅迅网络股份有限公司 一种基于Linux的多线程硬实时控制方法

Also Published As

Publication number Publication date
CN107690625B (zh) 2022-02-11
CN107690625A (zh) 2018-02-13

Similar Documents

Publication Publication Date Title
KR101503627B1 (ko) 리소스 세트 천이들을 스케줄링함으로써 휴대용 컴퓨팅 디바이스에 있어서의 프로세서 어플리케이션 상태들 간의 리소스 레이턴시의 최소화
US8954975B2 (en) Task scheduling method for real time operating system
CN106844017A (zh) 用于网站服务器处理事件的方法和设备
KR20140127341A (ko) 휴대용 컴퓨팅 디바이스에서 요청들을 스케쥴링하기 위한 방법 및 시스템
WO2020134830A1 (zh) 一种算法程序加载的方法及相关装置
JP2010272076A (ja) マルチプロセッサシステム
US20150234759A1 (en) Method and apparatus using high-efficiency atomic operations
CN100583047C (zh) 实时中断与多个进程状态同步的方法
WO2012087533A1 (en) Minimizing resource latency between processor application states in a portable computing device by using a next-active state set
JP4584935B2 (ja) 動作モデルベースマルチスレッドアーキテクチャ
WO2019000790A1 (zh) 一种以同步方式进行远程过程调用的方法及装置
WO2012152029A1 (zh) 利用同步函数调用机制实现多线程消息交互的方法和装置
WO2018165952A1 (zh) iOS线程恢复的方法及装置
WO2017101336A1 (zh) 快捷开关的控制方法及装置
JPH02300939A (ja) セマフォオペレーション方式
US9372723B2 (en) System and method for conditional task switching during ordering scope transitions
JP2006146758A (ja) コンピュータシステム
JPH11312148A (ja) バリア同期方法及び装置
CN112689827B (zh) 模型推理异常处理方法及装置
CN111638965B (zh) 基于栅栏复制与握手的命令队列间栅栏同步方法及系统
WO2020238967A1 (zh) 多线程退出方法及移动终端
JP4147087B2 (ja) 情報処理通信装置
CN109254834B (zh) 一种多线程启动同步方法
TWI357575B (zh)
WO2012088766A1 (zh) 一种用于动态调度批处理任务的方法和装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17900553

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 17.01.2020)

122 Ep: pct application non-entry in european phase

Ref document number: 17900553

Country of ref document: EP

Kind code of ref document: A1