[Ecls-list] Multithreaded globals

Dean O'Connor dean.oconnor at ite.com.au
Mon Nov 7 05:43:47 UTC 2005


hmmmm pity :)

Any thoughts on how much I can get away with without mutexes ?

Sorry if this seems obvious ....
For example, in the code below, if each of my threads called start(), 
straight away binding a newly created class object to that dynamic 
variable, is that threadsafe on a multi-cpu machine ?
Or do I *need* some mutexing to guarantee no clobbering ?

(defparameter *MyObj* nil)

(defclass MyClass () .....)

;; After ecl_import_current_thread(), this function is called as start 
of thread code logic:

(defun start ()
    (let ((*MyObj* (make-instance 'MyClass)))
       (setf (field *MyObj*) "stuff")
       (work)))

(defun work()
    (setf (field *MyObj*) "more stuff"))

Cheers
Dean

Juan Jose Garcia Ripoll wrote:

>On Mon, 2005-11-07 at 23:56 +1100, Dean O'Connor wrote:
>  
>
>>Hi
>>
>>I am still dualling with our multithreaded C app. So far 
>>ecl_import_current_thread() is working well :)
>>
>>I have been finding dynamic variables very useful and am keen to know 
>>what happens over multiple threads.
>>
>>In what way can I create a variable to be:
>>-  global across all threads ?
>>-  global within a thread ?
>>
>>So what happens to defparameter/var variables in the main thread vs ones 
>>created after calling ecl_import_current_thread() ?
>>    
>>
>
>Currently there is no such distinction between _main_ and _other_
>threads. This has an immediate consequence, which is that DEFPARAMETER
>and DEFVAR always establish global variable bindings which are common to
>_all_ threads.
>
>There are two situations in which you get local bindings:
>
>1) When you create a process with MAKE-PROCESS. There you can specify a
>list of variables that you want to be local to the process.
>
>2) When you make a LET/LET*/DO... binding, it is local to the thread.
>
>It may be a little bit inconvenient, but I did not come up with a better
>alternative without changing the syntax of DEFPARAMETER/DEFVARIABLE.
>
>Regards,
>
>Juanjo
>
>
>
>-------------------------------------------------------
>SF.Net email is sponsored by:
>Tame your development challenges with Apache's Geronimo App Server. Download
>it for free - -and be entered to win a 42" plasma tv or your very own
>Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
>_______________________________________________
>Ecls-list mailing list
>Ecls-list at lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/ecls-list
>  
>





More information about the ecl-devel mailing list