Quarto.Net in Mono启动线程冻结系统

时间:2012-11-14 17:00:54

标签: c# multithreading mono quartz.net

我在单声道中使用Quartz.net。 当我创建这样的调度程序时:

ISchedulerFactory quartzSchedulerFactory = new StdSchedulerFactory();
IScheduler quartzScheduler = quartzSchedulerFactory.GetScheduler();

在Quartz.Net中,在SimpleThreadPool类中调用以下方法:

/// <summary>
/// Called by the QuartzScheduler before the <see cref="ThreadPool" /> is
/// used, in order to give the it a chance to Initialize.
/// </summary>
public virtual void Initialize()
{
    if (workers != null && workers.Count > 0) 
    {
        // already initialized...
        return;
    }

    if (count <= 0)
    {
        throw new SchedulerConfigException("Thread count must be > 0");
    }

    // create the worker threads and start them
    foreach (WorkerThread wt in CreateWorkerThreads(count))
    {
        wt.Start();

        availWorkers.AddLast(wt);
    }
}

在Windows中,这可以正常工作,但在CentOS中,系统会在调用wt.Start()时冻结。即使我杀死了进程,它也会失效,只有重新启动系统才能杀死它。 虽然有时它可以正常工作,但我执行该程序大约有五分之一。

这是在WorkerThread启动时调用的代码:

public override void Run()
{
    bool ran = false;
    bool shouldRun;
    lock (this)
    {
        shouldRun = run;
    }

    while (shouldRun)
    {
        try
        {
            lock (this)
            {
                while (runnable == null && run)
                {
                    Monitor.Wait(this, 500);
                }

                if (runnable != null)
                {
                    ran = true;
                    runnable.Run();
                }
            }
        }
        catch (Exception exceptionInRunnable)
        {
            log.Error("Error while executing the Runnable: ", exceptionInRunnable);
        }
        finally
        {
            lock (this)
            {
                runnable = null;
            }
            // repair the thread in case the runnable mucked it up...
            if (Priority != tp.ThreadPriority)
            {
                Priority = tp.ThreadPriority;
            }

            if (runOnce)
            {
                lock (this)
                {
                    run = false;
                }
                tp.ClearFromBusyWorkersList(this);
            }
            else if (ran)
            {
                ran = false;
                tp.MakeAvailable(this);
            }
        }

        // read value of run within synchronized block to be 
        // sure of its value
        lock (this)
        {
            shouldRun = run;
        }
    }

    log.Debug("WorkerThread is shut down");
}

这可能是一个死锁问题吗?如果是的话,为什么不在Windows中发生?

由于

1 个答案:

答案 0 :(得分:3)

我在CentOs中遇到过类似的问题。 Mono 2.10.8.1坚持创建默认的线程池线程。卡住后,无法杀死进程或获取堆栈跟踪。

我已经设法通过更新操作系统的核心来解决问题。 从2.6.32-71.el6.x86_64到2.6.32-279.14.1.el6.x86_64。