[Spread-users] Win32 socket handle problems in multithreaded applications.

Dal, Mats Mats.Dal at dice.se
Tue Jun 17 07:30:13 EDT 2008


The mutex lock in "Sp.c" uses a dangerous assumption that doesn't hold on Win32. The mbox will be assigned the opened win32 socket handle that could be greater than 0xFF, and for most time is.

 

int        SP_connect_timeout( const char *spread_name, const char *private_name,

                          int priority, int group_membership, mailbox *mbox,

                          char *private_group, sp_time time_out )

{

.

s = socket( AF_UNIX, SOCK_STREAM, 0 );

.

*mbox = s;

}

 

 

The following code is bad on win32, masking with 0xFF will generate different socket handles using the same mutex and could cause deadlock during multithreaded applications.

 

int        SP_scat_receive( mailbox mbox, service *service_type, char sender[MAX_GROUP_NAME],

                                  int max_groups, int *num_groups, char groups[][MAX_GROUP_NAME],

                                  int16 *mess_type, int *endian_mismatch,

                                  scatter *scat_mess )

{

.

.

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

.

.

}

 

 

 

Mats Dal
Senior Software Engineer 1

Tel 861
Fax +46 8 658 78 99
Cell 0709-549851
Mats.Dal at dice.se <mailto:Mats.Dal at dice.se> 

DICE

EA Digital Illusions CE AB
Katarinavägen 15
P.O. Box 20068
SE-104 60 Stockholm, Sweden
www.dice.se <http://www.dice.se> 


Corporate Registration Number: 556710-6520 







  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.spread.org/pipermail/spread-users/attachments/20080617/ddd3dcc5/attachment.html 


More information about the Spread-users mailing list