How can i create a thread inside NEPacketTunnelProvider?

I want to make two seperate thread for reading date from socket inside tunnel network extension

Replies

Network Extension providers don’t place any specific limits on creating threads within the provider. You can use whatever threading API you want. In general I recommend:

  • NSThread
    (
    Thread
    in Swift) for most use cases
  • pthreads if you’re writing cross-platform code

WARNING A common mistake is to use dispatch to create a long-live thread. For example, something like this:

dispatch_async(dispatch_get_global_queue(…), ^{
    … block here indefinitely …
});

This is problematic because it ties up a dispatch worker thread doing stuff that’s not related to dispatch. If you want to create a long-lived thread for running some subsystem within your app, use a threading API not dispatch.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"