Skip to content

Instantly share code, notes, and snippets.

@ted80
Created October 15, 2015 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ted80/b7638beb30f366477d51 to your computer and use it in GitHub Desktop.
Save ted80/b7638beb30f366477d51 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System;
using System.Threading;
using System.Collections;
public class Test : MonoBehaviour
{
private Queue queueCalc;
private Queue queueMain;
private System.Random random;
void Awake ()
{
random = new System.Random ();
queueCalc = Queue.Synchronized(new Queue());
queueMain = Queue.Synchronized(new Queue());
/*
Thread thread = new Thread (new ThreadStart (run));
thread.IsBackground = true;
thread.Start ();
*/
}
void Update ()
{
/*
queueCalc.Enqueue (new Calculation(random.Next(1000), random.Next(1000)));
int i = 0;
while(queueMain.Count > 0)
{
i++;
queueMain.Dequeue();
}
Debug.Log (i);
*/
}
public void run()
{
while(true)
{
if(queueCalc.Count > 0)
{
Calculation c = (Calculation)queueCalc.Dequeue();
c.c = c.a + c.b;
queueMain.Enqueue(c);
}
else
{
Thread.Sleep(1);
}
}
}
}
class Calculation
{
public int a;
public int b;
public int c;
public Calculation(int _a, int _b)
{
a = _a;
b = _b;
c = 0;
}
}
@ted80
Copy link
Author

ted80 commented Oct 15, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment