source: trunk/src/gcc/libobjc/THREADS@ 1005

Last change on this file since 1005 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 14.7 KB
RevLine 
[2]1This file describes in little detail the modifications to the
2Objective-C runtime needed to make it thread safe.
3
4First off, kudos to Galen Hunt who is the author of this great work.
5
6If you have an comments or just want to know where to
7send me money to express your undying gratitude for threading the
8Objective-C runtime you can reach Galen at:
9
10 [email protected]
11
12Any questions, comments, bug reports, etc. should send email either to the
13GCC bug account or to:
14
15 Scott Christley <[email protected]>
16
17* Sarray Threading:
18
19The most critical component of the Objective-C runtime is the sparse array
20structure (sarray). Sarrays store object selectors and implementations.
21Following in the tradition of the Objective-C runtime, my threading
22support assumes that fast message dispatching is far more important
23than *ANY* and *ALL* other operations. The message dispatching thus
24uses *NO* locks on any kind. In fact, if you look in sarray.h, you
25will notice that the message dispatching has not been modified.
26Instead, I have modified the sarray management functions so that all
27updates to the sarray data structure can be made in parallel will
28message dispatching.
29
30To support concurrent message dispatching, no dynamically allocated
31sarray data structures are freed while more than one thread is
32operational. Sarray data structures that are no longer in use are
33kept in a linked list of garbage and are released whenever the program
34is operating with a single thread. The programmer can also flush the
35garbage list by calling sarray_remove_garbage when the programmer can
36ensure that no message dispatching is taking place concurrently. The
37amount of un-reclaimed sarray garbage should normally be extremely
38small in a real program as sarray structures are freed only when using
39the "poseAs" functionality and early in program initialization, which
40normally occurs while the program is single threaded.
41
42******************************************************************************
43* Static Variables:
44
45The following variables are either statically or globally defined. This list
46does not include variables which are internal to implementation dependent
47versions of thread-*.c.
48
49The following threading designations are used:
50 SAFE : Implicitly thread safe.
51 SINGLE : Must only be used in single thread mode.
52 MUTEX : Protected by single global mutex objc_runtime_mutex.
53 UNUSED : Not used in the runtime.
54
55Variable Name: Usage: Defined: Also used in:
56=========================== ====== ============ =====================
57__objc_class_hash MUTEX class.c
58__objc_class_links_resolved UNUSED class.c runtime.h
59__objc_class_number MUTEX class.c
60__objc_dangling_categories UNUSED init.c
61__objc_module_list MUTEX init.c
62__objc_selector_array MUTEX selector.c
63__objc_selector_hash MUTEX selector.c
64__objc_selector_max_index MUTEX selector.c sendmsg.c runtime.h
65__objc_selector_names MUTEX selector.c
66__objc_thread_exit_status SAFE thread.c
67__objc_uninstalled_dtable MUTEX sendmsg.c selector.c
68_objc_load_callback SAFE init.c objc-api.h
69_objc_lookup_class SAFE class.c objc-api.h
70_objc_object_alloc SINGLE objects.c objc-api.h
71_objc_object_copy SINGLE objects.c objc-api.h
72_objc_object_dispose SINGLE objects.c objc-api.h
73frwd_sel SAFE2 sendmsg.c
74idxsize MUTEX sarray.c sendmsg.c sarray.h
75initialize_sel SAFE2 sendmsg.c
76narrays MUTEX sarray.c sendmsg.c sarray.h
77nbuckets MUTEX sarray.c sendmsg.c sarray.h
78nindices MUTEX sarray.c sarray.h
79previous_constructors SAFE1 init.c
80proto_class SAFE1 init.c
81unclaimed_categories MUTEX init.c
82unclaimed_proto_list MUTEX init.c
83uninitialized_statics MUTEX init.c
84
85Notes:
861) Initialized once in unithread mode.
872) Initialized value will always be same, guaranteed by lock on selector
88 hash table.
89
90
91******************************************************************************
92* Frontend/Backend design:
93
94The design of the Objective-C runtime thread and mutex functions utilizes a
95frontend/backend implementation.
96
97The frontend, as characterized by the files thr.h and thr.c, is a set
98of platform independent structures and functions which represent the
99user interface. Objective-C programs should use these structures and
100functions for their thread and mutex work if they wish to maintain a
101high degree of portability across platforms.
102
103The backend is composed of a file with the necessary code to map the ObjC
104thread and mutex to a platform specific implementation. For example, the
105file thr-solaris.c contains the implementation for Solaris.
106
107If you are compiling libobjc as part of GCC, the thr-objc.c backend is
108always used; this backend uses GCC's gthread code. The thread system
109is automatically configured when GCC is configured. Important: make
110sure you configure GCC using `--enable-threads' if you want threads !
111
112If you want to compile libobjc standalone, then you would need to
113modify the configure.in and makefiles for it; and you need to pick an
114appropriate backend file for the target platform; you make this choice
115by assigning the OBJC_THREAD_FILE make variable to the basename of the
116backend file. For example, OBJC_THREAD_FILE=thr-posix would indicate
117that the generic posix backend file, thr-posix.c, should be compiled