Unix Technical Forum

Thread safety

This is a discussion on Thread safety within the MySQL General forum forums, part of the MySQL category; --> Dear All: I have a table T1 with these columns: location - varchar odd_even - varchar I have a ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 05:22 AM
Ravi Kumar.
 
Posts: n/a
Default Thread safety

Dear All:

I have a table T1 with these columns:

location - varchar
odd_even - varchar

I have a php page that is called from VC applications installed in 5
different locations (L1, L2, L3, L4 and L5). The page returns 0 or 1
depending on even call or odd call from each location. (1st, 3rd, 5th,
7th... page calls are odd and 2, 4, 6, 8 are even.)

The page has this logic:

select odd_even from T1 where location = '$location'

if (odd_even == 'odd')
update T1 set odd_even = 'even' where location = '$location' and
odd_even = 'odd';
return '0';
else
update T1 set odd_even = 'odd' where location = '$location' and
odd_even = 'even';
return '1';

But since each location calls the page in very quick succession (a location
have have several parallel calls running - its a multi threaded app), there
is a race condition. And at times several continuous calls return same
result (odd or even).

How do I achieve thread safety?

Please help. Its urgent.

Thanks.

Ravi.







Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 05:22 AM
Jerry Schwartz
 
Posts: n/a
Default RE: Thread safety

I'm pretty sure that the only way to do this is to use an engine (such as
InnoDB) that supports transactions across multiple statements. You need some
global resource that is single-threaded, and unless you have something in a
file system somewhere that supports locking there I don't see any ready way
to do this.

Remember, however unlikely any collision that might happen eventually will.
You can't fix this problem without a location-wide single-threaded resource.

Regards,

Jerry Schwartz
Global Information Incorporated
195 Farmington Ave.
Farmington, CT 06032

860.674.8796 / FAX: 860.674.8341


> -----Original Message-----
> From: Ravi Kumar. [mailto:ravi.kumar@cbayindia.com]
> Sent: Thursday, December 07, 2006 7:18 AM
> To: mysql@lists.mysql.com
> Subject: Thread safety
>
> Dear All:
>
> I have a table T1 with these columns:
>
> location - varchar
> odd_even - varchar
>
> I have a php page that is called from VC applications installed in 5
> different locations (L1, L2, L3, L4 and L5). The page returns 0 or 1
> depending on even call or odd call from each location. (1st, 3rd, 5th,
> 7th... page calls are odd and 2, 4, 6, 8 are even.)
>
> The page has this logic:
>
> select odd_even from T1 where location = '$location'
>
> if (odd_even == 'odd')
> update T1 set odd_even = 'even' where location =
> '$location' and
> odd_even = 'odd';
> return '0';
> else
> update T1 set odd_even = 'odd' where location =
> '$location' and
> odd_even = 'even';
> return '1';
>
> But since each location calls the page in very quick
> succession (a location
> have have several parallel calls running - its a multi
> threaded app), there
> is a race condition. And at times several continuous calls return same
> result (odd or even).
>
> How do I achieve thread safety?
>
> Please help. Its urgent.
>
> Thanks.
>
> Ravi.
>
>
>
>
>
>
>




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:25 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com