There's (effectively) no concurrency in node, no need to worry about that 
kind of complexity.

In your code below, "line" is a global variable, you're modifying it, so it 
gets added to the table under one key with the first values, then gets 
modified to the second values, and inserted again, but both of them are 
still referencing the same object, so they have the same value when you 
look them up in the table.  Adding line = [] to allocate a new object 
before you start filling it in should fix it.

On Monday, June 18, 2012 9:00:02 AM UTC-7, vitoa wrote:
>
> Hi, seems that I'm having some strange problems.. 
> Is there any problem on concurrency to that  object table when some 
> event sometimes write to it and other events sometimes read? 
>
> I have an event on serial data that grabs the incoming data and put 
> that in object table acording to unique mac key 
>
> sp.on("data",function(data){ 
> for(i=0;i<16;i++){ 
>                         mac[i]=data[6+i]; 
>                 } 
>                 for(i=0;i<2;i++) 
>                 { 
>                         rssi[i]=data[41+i]; 
>                 } 
>                 line[2]=(parseInt(rssi.join(""))); 
>                 line[1]=("aaaa"); 
>                 line[0]=(mac.join("")); 
>
>                 table[line[0]]=line; 
> } 
> I'm receiving constant data  so table[line[0]]=line, means that if mac 
> exists it replaces the  values, if does not exist it adds to table 
> with the values 
> But else in code is other events that read from this object table 
>
>
> in other event I've done some console log debug: 
>
> for(var key in table) 
>              {console.log(table[key]);} 
> console.log(Object.keys(table)[0]); 
> console.log(Object.keys(table)[1]); 
> console.log(table[Object.keys(table)[0]]+'   '+table[Object.keys(table) 
> [1]]); 
>
> The results  were: 
>
> [ '000D6F00015FF4BC', 'aaaa', 52 ] 
> [ '000D6F00015FF4BC', 'aaaa', 52 ] 
> 0021ED0000075385 
> 000D6F00015FF4BC 
> 000D6F00015FF4BC,aaaa,52   000D6F00015FF4BC,aaaa,52 
>
> That's not consistent data because there are 2 diferent mac in table, 
> it should show values form one mac and values from other mac instead 
> of showing the same mac data. 
> If mac is key, so I'm getting twice and it should't be happen. 
> But in console.log(Object.keys(table)[0]); and 
> console.log(Object.keys(table)[1]);  I simply get the the two macs Now 
> I'm confused. 
>
> Could that be a problem because concurrency that some event is 
> writting to table and sometimes the other events reads it? 
>
> Any ideia is welcome 
>
> Regards 
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to