[DSM-devel] On thread safety
Lars Wirzenius
liw at iki.fi
Fri Aug 25 22:58:56 EEST 2006
There are a number of operations on lists, and perhaps other data
structures, that need to be protected by a mutex (or other construct).
It is probably not a good idea to put the mutex into the list nodes,
because that creates a lot of them and also creates a lot of intricate
locking requirements, and will therefore fail to be simple enough to
work correctly in all situations. I don't think we need to add the
mutexes right now, though.
The dsme_sock_getucred function needs to be fixed to not use a static
variable, but that should be easy.
Here's a list of static variables in the current code.
dsmesock.c
static int as_lsock;
static dsme_list_node_t as_clients;
These are not necessarily a problem. There's probably not a need for
multiple instances of the listening socket in one process, for
example. It might be *prettier* to not have these two as
process-global variables, but they shouldn't really hurt as it is.
logging.c
static struct { ... } logopt;
static dsme_log_printer_t *printers[...];
static int num_printers;
These should be fine. There's no need to have different logging
options for different threads.
The dsme_log_add_custom_method, dsme_log_open, and dsme_log_reopen
functions are not re-entrant. That should be fixable via a simple
mutex, if it is deemed necessary.
modulebase.c
static dsme_list_node_t modules;
static dsme_list_node_t callbacks;
static dsme_list_node_t message_queue;
static const char *argv1;
These should be good, except for the mutex protection that is
needed.
protocol.c
static dsme_list_node_t connections;
static dsme_list_node_t pseudo_connections;
static int connectionlist_initialized;
The connectionlist_initialized variable should go away;
initialization should go into an initialization function that gets
called once at the beginning of the process. Operations on the lists
need mutex protection.
function dsme_sock_getucred:
static struct ucred pseudo_ucred;
This is just wrong. The static variable needs to be replaced by
something else.
spawn.c
static dsme_sock_connection_t *pseudoconnection;
OK, modulo a mutex.
timers.c
static dsme_list_node_t timers;
OK, modulo a mutex.
modules/busdebug.c
static module_t *my_handle;
static dsmesock_connection_t *my_conn;
static dsmesock_connection_t *connection;
OK, modulo a mutex.
modules/lifeguard.c
static char lg_reboot_enabled;
static dsme_module_t *my_handle;
static dsme_sock_connection_t *my_conn;
static dsme_list_node_t processes;
static dsme_list_node_t uids;
OK, modulo a mutex.
modules/processwd.c
static dsme_module_t *my_handle;
static dsme_sock_connection_t *my_conn;
static dsme_timer_t *timer;
static int interval;
static dsme_list_node_t processes;
OK, modulo a mutex.
modules/startup.c
static dsme_module_t *my_handle;
static dsme_sock_connection_t *my_conn;
OK, modulo a mutex.
--
Close your mind to stress and pain, hack till you're no longer sane.
More information about the DSM-devel
mailing list