[ create a new paste ] login | about

Link: http://codepad.org/n0HgKqy8    [ raw code | fork ]

C, pasted on May 9:
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Android.App;
using Android.Widget;
using Android.OS;

namespace AndroidApplication4
{
    [Activity(Label = "AndroidApplication4", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);
            Button button = FindViewById<Button>(Resource.Id.MyButton);
            button.Click += (s, e) => LinkedListTests();
        }

        private static async void LinkedListTests()
        {
            var tasks = new List<Task>();
            var linkedList = new LinkedList<string>();
            for (int i = 1; i < 1500; i++)
            {
                tasks.Add(Task.Run(() =>
                {
                    for (int j = 0; j < i; j++)
                    {
                        lock (linkedList)
                        {
                            linkedList.AddLast("foo"); 
                        }
                        lock (linkedList)
                        {
                            linkedList.AddFirst("aaa"); 
                        }
                    }
                    lock (linkedList)
                    {
                        linkedList.Clear(); 
                    }
                }));
            }
            await Task.WhenAll(tasks);
        }
    }
}


Create a new paste based on this one


Comments: