Wednesday, December 26, 2012

java.util.ConcurrentModificationException False belief

Dear all,


I faced the exception

java.util.ConcurrentModificationException

Immediately I started thinking ..., since two different functions{A() and B()} are executing parallel, some critical section variable might be accessed at the same time by both functions A() and B().

So to solve the issue, I used java function 'synchronized() {  } ' blocks inside both the functions A() and B().  But surprisingly the error was not solved.

Thanks to the link

http://stackoverflow.com/questions/8189466/java-util-concurrentmodificationexception

which told me that, the concurrent exception happens because of the Iterator I used in one of the function A().

Consider the program

 ------------------------------------------------------------------------------

set= myhashmap.entrySet();

i=set.Iterator();

while (i.hasNext())

      {

       myhashmap.remove(datanode);//This causes problem

        }

  --------------------------------------------------------------------------------------------------

 

'i' has already Iterator set values and pointers/ memory locations assigned to it.  But when you remove an item from hashmap, the 'i' is not getting updated(i =set.Iterator() is not called inside while).  So when while(i.hasNext () ) is checking for datanode location, it finds that somebody else has already removed/modified the data in that location.  So it thinks that Some body(some other program) is accessing the memory(critical section) alloted to it.  Hence shouts ConcurrentModificationException

Tuesday, June 26, 2012

Simple DLL for visual basic 2010 calculator

Steps to make a DLL Calculator

CREATING A DLL

Prerequist: Visual Studio 2010.
1. Open Visual Studio 2010
2. New Project--->  VC++---->MFC DLL
3. Give name to your dll project say "dllsampleadd"
4. OK creates new project
5. Delete all contents in dllsampleadd.cpp
6. Add the following contents:

#include "stdafx.h"
int _stdcall sum(int x , int y)
{
return x+y;
}


7. Open file dllsampleadd.def
8. Update the contents of dllsampleadd.def to

LIBRARY DLLSAMPLEADD

EXPORTS
sum @1








9. Build ---> Build Solution
10. You can see the DLL file 'dllsampleadd.dll' getting created at the Debug folder of your project

 VISUAL BASIC APPLICATION


1. File ---> NewProject --->  Other languages---> Visual Basic--->Windows Forms Application
2. Give name to your dll project say "add"
3. Drag and drop buttons and labels as shown in screenshot
 4. Double click on add button.
5. Make necessary changes to the code associated with add button as given below:

Private Declare Function sum Lib "C:\Users\hari\Documents\Visual Studio 2010\Projects\dllsampleadd\Debug\dllsampleadd.dll" (ByVal x As Int32, ByVal y As Int32) As Int32
    Private Sub Button1_Click() Handles Button1.Click
        Label4.Text = Str(sum(CInt(TextBox1.Text), CInt(TextBox2.Text)))
    End Sub


6. Run your program( Debug---->Start Debugging)
7. Make necessary changes to your dll program and VB program for adding subract, divide, multiply functions to the calculator.

Tuesday, May 15, 2012

TinyOS : problem in installing cygwin


SITUTATION :Running following command in Cygwin
                rpm -Uvh --ignoreos nesc-1.2.8a-1.cygwin.i386.rpm

Error :" unpacking of archive failed on file usr cpio: chmod failed permission denied"

SOLUTION: Right click Cywin start up file---> Run as administrator