Register for your free account! | Forgot your password?

You last visited: Today at 11:49

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Src]ActionQueue

Discussion on [Src]ActionQueue within the CO2 PServer Guides & Releases forum part of the CO2 Private Server category.

Reply
 
Old 02/07/2012, 20:01   #16
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Quote:
Originally Posted by Fаng View Post
Nah. This is mine:
Code:
    public sealed class ThreadedQueue
    {
        // Configuration:
        private readonly object _locker;
        private Thread[] _workers;
        private Queue<Action> _queue;

        public ThreadedQueue(int workerCount)
        {
            _locker = new object();
            _queue = new Queue<Action>();
            _workers = new Thread[workerCount];
            for (int i = 0; i < workerCount; i++)
                (_workers[i] = new Thread(Dequeue)).Start();
        }
        private void Dequeue()
        {
            while (true)
            {
                Action obj;
                lock (_locker)
                {
                    while (_queue.Count == 0) 
                        Monitor.Wait(_locker);
                    obj = _queue.Dequeue();
                }
                if (obj == null)
                    return;
                obj();
            }
        }
        public void Enqueue(Action method)
        {
            lock (_locker)
            {
                _queue.Enqueue(method);
                Monitor.Pulse(_locker);
            }
        }
        public void Shutdown(bool waitForWorkers)
        {
            foreach (Thread worker in _workers)
                Enqueue(null);
            if (waitForWorkers)
                foreach (Thread worker in _workers)
                    worker.Join();
            _workers = null;
            _queue = null;
        }
    }
Yours are not doing same thing as mine tho. The wrapper you have is for a thread queue with a lot threads to handle, mine is one thread with a queue of objects to handle.
I don't have a username is offline  
Old 02/07/2012, 20:07   #17
 
Spirited's Avatar
 
elite*gold: 12
Join Date: Jul 2011
Posts: 8,282
Received Thanks: 4,191
Quote:
Originally Posted by I don't have a username View Post
Yours are not doing same thing as mine tho. The wrapper you have is for a thread queue with a lot threads to handle, mine is one thread with a queue of objects to handle.
Yep. That's my action queue though. The only time that I'd use a single threaded queue is if I was outputting something to one, shared resource.
Spirited is offline  
Old 02/07/2012, 20:29   #18
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Quote:
Originally Posted by Fаng View Post
Yep. That's my action queue though. The only time that I'd use a single threaded queue is if I was outputting something to one, shared resource.
What about for stamina and so on? You have a thread for every player? o.o
I don't have a username is offline  
Old 02/07/2012, 21:50   #19


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
His is basically a threadpool, so its not 1 thread per player, they just share the work load.
Korvacs is offline  
Thanks
2 Users
Old 02/08/2012, 00:18   #20
 
Spirited's Avatar
 
elite*gold: 12
Join Date: Jul 2011
Posts: 8,282
Received Thanks: 4,191
Quote:
Originally Posted by Korvacs View Post
His is basically a threadpool, so its not 1 thread per player, they just share the work load.
Exactly. It's what I use for loading maps or managing high amounts of work.
Spirited is offline  
Reply




All times are GMT +1. The time now is 11:50.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.