apposed / jaunch

Launch Programs 𝙔𝙤𝙪𝙧 Way! 🍔
The Unlicense
6 stars 2 forks source link

Launch on separate thread #22

Closed ctrueden closed 3 months ago

ctrueden commented 4 months ago

The ImageJ Launcher uses pthread_create and CFRunLoopSourceCreate to start the JVM on a dedicated thread:

/* MacOSX needs to run Java in a new thread, AppKit in the main thread. */

static void dummy_call_back(void *info) { }
...
pthread_t thread;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

/* Start the thread that we will start the JVM on. */
pthread_create(&thread, &attr, start_ij_aux, NULL);
pthread_attr_destroy(&attr);

CFRunLoopSourceContext context;
memset(&context, 0, sizeof(context));
context.perform = &dummy_call_back;

CFRunLoopSourceRef ref = CFRunLoopSourceCreate(NULL, 0, &context);
CFRunLoopAddSource (CFRunLoopGetCurrent(), ref, kCFRunLoopCommonModes);
CFRunLoopRun();

Should Jaunch also do this?