replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - .NET DLL and common block variables
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

.NET DLL and common block variables

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
Abhishek



Joined: 22 Dec 2010
Posts: 28

PostPosted: Sat Jan 08, 2011 6:46 pm    Post subject: .NET DLL and common block variables Reply with quote

Hi

I am creating a .NET dll from existing source code. The existing source code has some common block variables for passing data between subroutines.

As I understand, all functions and common block variables will be static. In such a case, if multiple threads call the same function, results may be jumbled up due to these common block variables.

Is there a solution to the above problem ?

Thanks
Abhishek
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Mon Jan 10, 2011 10:22 am    Post subject: Reply with quote

Are you sure that you mean multiple "threads". You proably mean multiple "processes" in which case there will be no problem.

You only used multiple threads when you intend to use the same common data. You can do this and there is information about this in the help file.
Back to top
View user's profile Send private message AIM Address
Abhishek



Joined: 22 Dec 2010
Posts: 28

PostPosted: Mon Jan 10, 2011 2:57 pm    Post subject: Reply with quote

I mean multiple threads because I have a dll that is called inside a VB.NET executable.

The common block variables exist in the legacy code that I converted to dll and are used to access shared data by the subroutines inside the dll.

My question is whether there is some way to encapsulate these subroutines inside a class so that I can instantiate a different object for each thread.
Back to top
View user's profile Send private message
Abhishek



Joined: 22 Dec 2010
Posts: 28

PostPosted: Fri Jan 14, 2011 12:00 pm    Post subject: Reply with quote

Any ideas on this one ?
Back to top
View user's profile Send private message
DrTip



Joined: 01 Aug 2006
Posts: 74
Location: Manchester

PostPosted: Fri Jan 14, 2011 2:53 pm    Post subject: Reply with quote

Not done a lot of threading with FTN95.Net but...

as with any .net threading application accessing the same data block you need to control the order of program flow using locks and mutators etc.

I don't have an example link to give you but my book Professional C# 2005 with .NET 3.0 by Nagel et al has a good chapter on this. (Chpater 1Cool

You don't really give enough info to give a proper answer.

basically you need to identify which blocks of code should only be called by a single thread at any one time and lock out the other threads.

There are .NET objects for this Mutex and Monitor which I guess you could use from FTN95.NET if you need to (though I would try and veer against this if you can) , I would always try and minimise the amount of data that needs to be accessed by multiple threads before resorting to using them,
Back to top
View user's profile Send private message
Abhishek



Joined: 22 Dec 2010
Posts: 28

PostPosted: Fri Jan 14, 2011 3:17 pm    Post subject: Reply with quote

Actually I have some FORTRAN functions/subroutines which have lot of common block variables. These common block variables are required so that subroutines can share data.

I am calling some of these functions from my main program (VB.NET) and these inturn call some other subroutines .. so its really a complex network of subroutines where it is impossible to reduce no. of common block variables.

In such a case, if I have to lock some portion of code, it really means all functions have to be single threaded.

I was looking for a solution where I can somehow encpsulate all of these functions and shared variables inside an object. So I can instantiate multiple objects and assign one object to each thread that needs to access these functions.

I hope its more clear now.

Thanks
Back to top
View user's profile Send private message
DrTip



Joined: 01 Aug 2006
Posts: 74
Location: Manchester

PostPosted: Fri Jan 14, 2011 4:04 pm    Post subject: Reply with quote

Well I am not sure I can help, other than to comment that it sounds like you have an over use of common block stuff to share data, i.e. use more parameters.

I don't think classes are part of FTN95 yet. but you can do some of what you want using modules rather than common blocks.

http://www.clear.rice.edu/mech517/F90_docs/EC_oop_f90.pdf

but how this would pan out with threads I don't know. Sorry I will let one of my more experienced and learned friends take up the slack form here I think


Carl
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Fri Jan 14, 2011 4:39 pm    Post subject: Reply with quote

The fact that you have a dll that is called inside a VB.NET executable does not mean that you need to use threading.

For each instance of your VB executable you will get an independent copy of the dll data base. You can even use LoadLibrary in the VB code to make sure that the dll is not unloaded whilst the executable is running but I doubt if this is necessary.
Back to top
View user's profile Send private message AIM Address
Abhishek



Joined: 22 Dec 2010
Posts: 28

PostPosted: Fri Jan 14, 2011 5:02 pm    Post subject: Reply with quote

I dont need to use threading for calling the dll.

I *want* to use threading to speed up execution, to execute two calculations in parallel rather than sequentially.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Sat Jan 15, 2011 9:33 am    Post subject: Reply with quote

I which case the solution to your original question is to use the locking mechanism described in FTN95.chm. See .NET Platform->.NET Programming->Threads and Synchronising Threads, assuming of course that you have at least a dual core processor on your machine.
Back to top
View user's profile Send private message AIM Address
Abhishek



Joined: 22 Dec 2010
Posts: 28

PostPosted: Sat Jan 15, 2011 2:46 pm    Post subject: Reply with quote

I had read that article.

LOCK is probably not an option here because practically the whole code would be under LOCK ! ... which effectively means calculation will be sequential anyways. Sequential calculation can be ensured by other means ... from the calling code.

FTN95 currently produces a class, lets say clsCalc, and then i call the methods like clsCalc.foo where foo is a method in clsCalc

If it is possible to instead be able to use something like:
Dim obj1 as clsCalc
obj1 = new clsCalc
and then call obj1.foo,
all variables etc will be specific to obj1 and I can create obj2 for Thread2.

Is above possible ?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Sat Jan 15, 2011 5:07 pm    Post subject: Reply with quote

If data is shared by two or more threads then you must use lock. You have no options about this.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group