When ButtonAction "1" is pressed, one loop occurs.
In that loop, communication processing is performed periodically.
Even when ButtonAction "2" is pressed, communication processing is performed.
The problem is that the timing of the two communications should not overlap.
Create a new queue and process it.
In order not to stop the main thread.
@IBAction func Button_Action1(_ sender: Any) {
Dispatch.queue_1.addOperation({ () -> Void in
while (true == Control_Flag) {
Dispatch.semaphore.wait() /* I want timeout */
/* Communication processing */
Dispatch.semaphore.signal()
usleep(50000)
}
})
}
}
@IBAction func Button_Action2(_ sender: Any) {
Dispatch.queue_2.addOperation {
Dispatch.semaphore.wait() /* I want timeout */
/* Commuication processing */
Dispatch.semaphore.signal()
usleep(50000)
}
}