[Spread-users] SP_receive bug on Windows 2000?

Massimo Feola massimo.feola at gatelab.com
Mon Jun 6 13:00:03 EDT 2005


I am using spread release 3.17.3 to develop a Windows 2000 multithread
application that establishes more than one spread connection with the same
spread agent and I believe to have found and fixed a few  spread bugs.

Each thread in my process establishes its own spread connection calling
SP_connect function and then keeps on calling the SP_receive function
waiting for data.

Occasionally I have experienced my threads to block incorrectly in the
SP_receive function.

Looking at the implementation of the SP_scat_receive function (file sp.c
line 1066) I noted that it uses the following critical section:

Mutex_lock( &Mbox_mutex[mbox & MAX_MUTEX_MASK][1] );

- Mbox_mutex is a matrix of MAX_MUTEX*2 elements
- MAX_MUTEX value is 256 (file sp.c line 88)
- MAX_MUTEX_MASK value is 0x000000ff (file sp.c line 89)

In Windows 2000 the values for MAX_MUTEX and for MAX_MUTEX_MASK do not
guarantee that for each value of mbox there is one and only one value of
"mbox & MAX_MUTEX_MASK][1]"; in fact in Windows 2000 the int data type size
is 4 bytes and a mbox may assume values greater than 255.
For example, for the mbox values 1228 and 716 the "mbox &
MAX_MUTEX_MASK][1]" value is 204. In this case the thread calling the
SP_receive function on mbox 1228 uses the same critical section of mbox 716
and could stop incorrectly.

In order to fix this problem I changed the value of MAX_MUTEX to 0xffff and
the value of MAX_MUTEX_MASK to 0x0000ffff

I have also added the following instruction in file sp.c:

- Mutex_lock( &Mbox_mutex[mbox & MAX_MUTEX_MASK][1] );

at line 1170 before the istruction 'return( ILLEGAL_MESSAGE );'
at line 1179 before the istruction 'return( ILLEGAL_MESSAGE );'
at line 1185 before the istruction 'return( ILLEGAL_MESSAGE );'

Did anyone experience my same problems or can tell me if the previous fixes
are appropriate ?


Massimo Feola"

More information about the Spread-users mailing list