public void AtomicDataResource_Allocate_Deallocate_InJob()
    {
        const int MAX      = 5000;
        var       resource = new AtomicFloatResource(MAX, Allocator.Persistent);
        var       holder   = new NativeArray <AtomicFloat>(MAX, Allocator.Persistent);
        var       job0     = new Job0()
        {
            resource = resource,
            holder   = holder,
        };

        job0.Schedule(MAX, 32).Complete();
        Assert.AreEqual(MAX, resource.getCountInUse());

        var job1 = new Job1()
        {
            resource = resource,
            holder   = holder,
        };

        job1.Schedule(MAX, 32).Complete();
        Assert.AreEqual(0, resource.getCountInUse());

        holder.Dispose();
        resource.Dispose();
    }
Ejemplo n.º 2
0
    public void NativeLimitedCounter_OverTheNumber()
    {
        const int MAX     = 1000;
        var       counter = new NativeLimitedCounter(Allocator.Persistent);
        var       job     = new Job1();

        job.counter = counter;
        job.maximum = MAX;
        job.Schedule(MAX * 2, 32).Complete();

        Assert.AreEqual(MAX, counter.Count);
        counter.Dispose();
    }
Ejemplo n.º 3
0
    void JobTest()
    {
        //NativeArray<int> nativeArray = new NativeArray<int>(1, Allocator.TempJob);
        //Job1 tempJob = new Job1() { i = 6, j = 7, result = nativeArray };
        Job1 tempJob = new Job1()
        {
            i = 6, j = 7
        };
        JobHandle jobHandle = tempJob.Schedule();

        jobHandle.Complete();

        Debug.Log(tempJob.result);
        //nativeArray.Dispose();
    }
Ejemplo n.º 4
0
    void MultiJobTest()
    {
        float tempStart = Time.realtimeSinceStartup;

        NativeList <JobHandle> nativeList = new NativeList <JobHandle>(Allocator.TempJob);

        for (int i = 0; i < 10; ++i)
        {
            Job1 tempJob = new Job1()
            {
                i = 6, j = 7
            };
            nativeList.Add(tempJob.Schedule());
        }

        JobHandle.CompleteAll(nativeList);
        nativeList.Dispose();

        float tempSumTime = Time.realtimeSinceStartup - tempStart;

        Debug.Log("ThreadSumTime: " + tempSumTime);
    }