Data leaking across threads

smol84

Client
Регистрация
06.01.2012
Сообщения
30
Благодарностей
2
Баллы
0
I make my projects in Code Creator, so I can fix this but for those who don't this could be a problem for Project maker also.

I notice that when I make projects with the record function it automatically declares the classes as internal and then the methods as public. This means that any thread with the same class can access the data in that method. As the zenno class refers to the entire project this means that any thread that is being run for that project can see the variables defined in any public method. If you use the recorder then EVERY class is public and therfore leaks data across threads.

The way around this is to implement thread safe coding practices, declare methods as private - not public. Also any variables such as strings, tables, int, var etc etc should also be declared public
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 771
Благодарностей
1 183
Баллы
113
I guess that there is exactly problem what I reported many times, but I did not had any proof of this.
I wrote that one thread taking data form other thread and this results in error.

I hope that eventually this problem will be discussed and resolved...

Cheers
 

darkdiver

Administrator
Команда форума
Регистрация
13.01.2009
Сообщения
2 284
Благодарностей
2 728
Баллы
113
What are talking about? Each thread has its' own instance of the project class.
There is no difference is the field of the class public or private.
If you do not have reference to the object you do not have access to its fields.
May be I don't understand what are you talking about. Please show me the code sample.
And again each thread has it's own instance of the project class. It does not have static fields or properties to common for each thread.
 

smol84

Client
Регистрация
06.01.2012
Сообщения
30
Благодарностей
2
Баллы
0
What are talking about? Each thread has its' own instance of the project class.
There is no difference is the field of the class public or private.
If you do not have reference to the object you do not have access to its fields.
May be I don't understand what are you talking about. Please show me the code sample.
And again each thread has it's own instance of the project class. It does not have static fields or properties to common for each thread.
I guess it will depend how zenno launches each instance. Typically when multithreading with c# any class defined as "internal class ClassName" will allow all methods defined as public or public static to be accesible to any thread which is run on the same assembly, and I assume that each thread uses the same project assembly?

E.g. from http://msdn.microsoft.com/en-us/library/ms173121.aspx

public
The type or member can be accessed by any other code in the same assembly or another assembly that references it.

private
The type or member can be accessed only by code in the same class or struct.

protected
The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.

internal
The type or member can be accessed by any code in the same assembly, but not from another assembly.

Am I wrong if I assume that because zenno uses "internal" that any class or method running within the same assembly will see data from the other threads? (assembly being the project created in PM or CC)???

For me it works ok because I have changed the code to access my class and methods with a public initialiser and then private methods. Is this wrong? Should I not do this?
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 771
Благодарностей
1 183
Баллы
113

darkdiver

Administrator
Команда форума
Регистрация
13.01.2009
Сообщения
2 284
Благодарностей
2 728
Баллы
113
Ok, here is the code sample.
Everything is public

C#:
using System;
using System.Threading;


namespace TestConsoleApplication
{
    class Program
    {
        public class Project
        {
            public string ProjectName;
        }

        public static Thread ThreadA;
        public static Thread ThreadB;

        private static void Main(string[] args)
        {
            ThreadA = new Thread(ThreadFunc);
            ThreadB = new Thread(ThreadFunc);
            ThreadA.Start(new Project {ProjectName = "ProjectA"});
            ThreadB.Start(new Project {ProjectName = "ProjectB"});
            ThreadA.Join();
            ThreadB.Join();
            Console.ReadKey();
        }

        public static void ThreadFunc(object parameter)
        {
            var project = parameter as Project;
            if (project != null) Console.WriteLine(project.ProjectName);
        }
    }
}
How you can get from ThreadB the project object from ThreadA without reflection?
Even if everything is public you do not have access to the variable until you do not have link to it.
 

allsystems

Client
Регистрация
08.07.2013
Сообщения
81
Благодарностей
1
Баллы
8
Hi Guys, this is something that I have been struggling with for the last week and just sent DD and PM about it. I am working on a template where the accounts are in an XLS file. If two threads use the same account it gets banned for a while before being allowed to be able to use it again. This is the code I am using:
C#:
IZennoTable table = project.Tables["API"];
{Lock (SyncObjects.TableSyncer)
{
var row = table.GetRow(0);
  
    // join items via "|"
    string result = String.Join("\t", row);
  
    table.DeleteRow(0);
  
    // and return this value
    return result;  
}
}
I have showed this to someone who is a C# expert and he says that the reason it dosent work is because each thread places the lock but does not communicate to other threads that a lock is placed. That is why duplicates are taken. The "Get Line" and "Remove after taking" does not work as it takes duplicates which I why I had to go to C#. This is something that is really frustrating me and needs to be resolved. I would be grateful if DD or another experienced Zenno person can chime in on how to fix this.

Thanks
 
Последнее редактирование модератором:

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)