Lisp HUG Maillist Archive

LWM: Cocoa, the main thread, and initialize-multiprocessing

Hello,

I was curious if anyone has managed to build a "pure" Cocoa; using  
NSApplication directly, with multiprocessing enabled? If  
multiprocessing is not enabled then creating an NSApplication  
instance and telling it to run works just fine because it is being  
done from the initial thread.

So far I haven't found a way the start multiprocessing (implicitly or  
explicitly) and get my call to (objc:invoke *application* "run") to  
actually run from the initial thread ("main" in Apple's documentation)

Does any have any ideas?

If I deliver an image with multiprocessing enabled then my code seems  
to always be called from the third thread created by LW. If I try to  
call (mp:initialize-multiprocessing) I get stuck because it doesn't  
return but I have to call it before control is passed off to the  
NSApplication instance.

The LW environment is able to get the Cocoa event loop running on the  
main thread somehow (just look at it using ThreadViewer.app) so  
obviously it is possible.

Thanks,

-greg

(I'm using LWM 4.4.5 Pro on Mac OS X 10.4.1)

Attached below is one of the various attempts I've made.

cocoa-application.lisp
=================================
(defparameter *frameworks-to-initialize*
   '("/System/Library/Frameworks/Foundation.framework/Versions/C/ 
Foundation"
     "/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa"
     :darwin-lw-objc))

(defvar *application* nil)
(defvar *delegate* nil)
(defvar *cocoa-event-loop-process* '("Coca Event Loop" nil run- 
application))

(progn
   (pushnew *cocoa-event-loop-processes* mp:*initial-processes*))

(defun start-application ()
   ;; initialize objc runtime
   (objc:ensure-objc-initialized :modules *frameworks-to-initialize*)

   ;; create app, load main nib, run event loop
   (setf *application* (objc:invoke "NSApplication"  
"sharedApplication"))
   (mp:initialize-multiprocessing))

(defun run-application ()
   (objc:invoke *application* "run"))
=====================================

deliver.lisp
=====================================
(in-package "CL-USER")

(load-all-patches)
(load (sys:example-file "configuration/macos-application-bundle.lisp"))

(load "cocoa-application")

(format t "~%~A~%" mp:*initial-processes*)

(deliver 'start-application
      (write-macos-application-bundle
       "~/Test"
       :template-bundle "/Applications/LispWorks 4.4.5/Library/lib/ 
4-4-0-0/examples/delivery/macos/templates/FullApplication.app/")
      0
      :interface nil
      :multiprocessing nil)
=======================================


Re: LWM: Cocoa, the main thread, and initialize-multiprocessing

Unable to parse email body. Email id is 4275

Updated at: 2020-12-10 08:52 UTC