Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create threads from a dispatch queue block [ swift / c++ ]

I have an iOS app, where the UI is written in swift, but all the heavy work is done with a cross platform c++ library. I communicate with the c++ core from swift using a ObjC wrapper.

I wanted to parallelize the work that is happening in the c++ library, using the thread primitives that c++ provides.

But a piece of data is passed into the c++ library from the swift portion of the app, from within a block in a dispatch queue.

My question is, will those threads that I create within the c++ library be separate from the work queue in swift ? From what I understand, it will be. Is that the case ?

Are there any open-source projects which does something similar, or any pitfalls you see with this approach.

The C++ library is a requirement and I can't make it swift only.

like image 324
nnrales Avatar asked Oct 16 '22 23:10

nnrales


1 Answers

will those threads that I create within the c++ library be separate from the work queue in swift ?

The answer is yes. I'm doing the same things for my app. For C++ library, I believe you will create threads with pthread_create() POSIX call. As found in Apple's doc, POSIX threads are totally legal in iOS and the only way to create joinable threads.

like image 61
beshio Avatar answered Nov 15 '22 07:11

beshio