User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: .Net Bug with threads ?

  1. #1
    No Products Registered

    Join Date
    Jun 2006
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .Net Bug with threads ?

    I finally managed to reproduce this bug that gave me much trouble !

    It seems it only appears using threads, that's why this script might seem mad (I have MMF launch a Main function which launches a new thread which launches another one regularly). The problem happens when I try to retrieve a parameter from an immediate condition : from times to times, it doesn't return the specified param.

    Launch the app, press space and watch the result, most of the lines are correctly written ("Condition Parameter : my parameter"), others might show the bug("ą§īCondition Parameter : my parameter" or such). If this doesn't show up the first time, press space again, it happens from time to time.

    Is there a way to prevent this from happening (I really need multi-threading) ? Is it because of .Net extension, or should I use Mutex or something ?
    Attached files Attached files

  2. #2
    Forum Moderator Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)

    Join Date
    Jun 2006
    Location
    Australia
    Posts
    682
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: .Net Bug with threads ?

    I dare say, this has to do with mmf's runtime not being really meant to deal with multiple threads.
    It also has to do with how the extension temporarily stores an 'Interaction Condition's parameter(s). (mostly)

    I'll add this as something to fix in a future version.

    Put a lock around the CallImmediateCondition() line. That should solve your problem.


  3. #3
    No Products Registered

    Join Date
    Jun 2006
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: .Net Bug with threads ?

    Thanks for the help, and fast answer.

    I wasn't able to fix the problem, but i've never used locks before, maybe I did something wrong. Should this be ok ?
    string[] param=new string[1]{"my parameter"};
    lock (param){
    MMFInterface.Conditions.CallImmediateCondition("Co ndition",param);
    }
    It doesn't seem to work.

  4. #4
    Forum Moderator Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)

    Join Date
    Jun 2006
    Location
    Australia
    Posts
    682
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: .Net Bug with threads ?

    No that's not ok cause you're creating a new object each function, which is useless.
    Create a static object in the BackForth class, a module-level declaration (make sure it's instantiated).
    Then get a lock on that.
    That way, if you've got 1000 threads all going on at once, they're all trying to get a lock on the same variable, so they won't step on eachother's toes. So to speak.

    Code:
     class BackForth {
       static Object o = new Object();
       ...
    Code:
     
       public static void test() {
       	lock (o)
    	{	
    	    MMFInterface.Conditions.CallImmediateCondition("Condition",new string[1]{"my parameter"});
    	}
       }

  5. #5
    Forum Moderator Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)

    Join Date
    Jun 2006
    Location
    Australia
    Posts
    682
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: .Net Bug with threads ?

    I've noticed some strange characters still appear sometimes, but at least it doesn't crash anymore.
    I think this is mmf2's fault or the rich edit box's fault. If you instead, add the returned parameter to a listbox, the problems seem to go away.

  6. #6
    No Products Registered

    Join Date
    Jun 2006
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: .Net Bug with threads ?

    I never had a crash here...

    Using the list object makes things better, but it's not perfect yet, sometimes a line is not added (this only happened to me once, with more than 4000 immediate conditions, so this might be hard to reproduce).

    Do you still think this issue could be fixed in a future version ?

  7. #7
    Forum Moderator Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)

    Join Date
    Jun 2006
    Location
    Australia
    Posts
    682
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: .Net Bug with threads ?

    Maybe it was crashing for me because I have dual cores? Synclocking fixes that.
    Anyway, I think some of the clickteam people could help you from here .

  8. #8
    No Products Registered

    Join Date
    Jun 2006
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: .Net Bug with threads ?

    I hope this gets fixed some way, I'd love to see a C# multithreaded server available for MMF, and it will need to be reliable.

    For now I'll stick to the List object to retrieve my parameters. By the way, it would be handy to have a "Last triggered ImmediateCondition Name" expression : this way you could create a "ParamParser" Loop which could retrieve the parameters of any ImmediateCondition (I know it's easy to have a string keep this information, but it would be easier).

  9. #9
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Jun 2006
    Posts
    6,773
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: .Net Bug with threads ?

    The only person who can help you is Greyhill. He will need to add multithreading support into his extension, so that MMF is only dealt with in HandleRunObject and not in other threads.

  10. #10
    No Products Registered

    Join Date
    Jun 2006
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: .Net Bug with threads ?

    After working a bit on this problem, i found a workaround :

    The problem is that you can only use CallImmediateCondition() from MMF thread, so I stored every event that should trigger such a callback in a container, and asked MMF to Always CallFunction("TriggerConditions",""). This way, all the ImmediateConditions will be called from inside MMF thread. Here is a simple example :

    Code:
    static class Global {
    
       //ATTRIBUTES
       private static Mutex MutexMMF=new Mutex();
       private static ArrayList Conditions=new ArrayList();
    
    public static void AddCondition(string nom, string[] param) {
       MutexMMF.WaitOne();
       Conditions.Add(new MMFCondition(nom, param));
       MutexMMF.ReleaseMutex();
    }//Adds a MMFCondition inside Conditions
    
    public static void TriggerConditions() {
       MutexMMF.WaitOne();
       foreach(MMFCondition c in Conditions) {
          MMFInterface.Conditions.CallImmediateCondition(c.nom, c.param);
          //Console.WriteLine(c.nom+" : "+c.param[0]+"||"+c.param[1]);
       }
       Conditions.Clear();
       MutexMMF.ReleaseMutex();
       }//Triggers all the MMFImmediateConditions Stored in Conditions
    
    }
    
    class MMFCondition {
       //attributes
       private string _nom;
       private string[] _param;
    
       //properties
       public string nom {
          get { return _nom; }
       }//public, read only
       public string[] param {
          get { return _param; }
       }//public, read only
    
       //constructor
       public MMFCondition(string nom, string[] param) {
          _param=new string[param.Length];
          _nom=nom;
          param.CopyTo(_param, 0);
       }
    
    }//Our condition class to trigger an MMFInterface.CallImmediateCondition
    This seems to work perfectly here, without any list object to retrieve the params

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •