What “thread safe” really means…In Practical terms

前端 未结 7 891
再見小時候
再見小時候 2021-01-30 13:24

please bear with my newbie questions..

I was trying to convert PDF to PNG using ghostscript, with ASP.NET and C#. However, I also read that ghostscript is not thread saf

相关标签:
7条回答
  • 2021-01-30 13:51

    1) It means if you share the same Ghostscript objects or fields among multiple threads, it will crash. For example:

    private GhostScript someGSObject = new GhostScript();
    ...
    // Uh oh, 2 threads using shared memory. This can crash!
    thread1.Use(someGSObject);
    thread2.Use(someGSObject);
    

    2) I don't think so - multithreaded rendering suggests GS is internally using multiple threads to render. It doesn't address the problem of GS being unsafe for use from multiple threads.

    3) Is there a question in there?

    To make GhostScript thread safe, make sure only 1 thread at a time is accessing it. You can do this via locks:

    lock(someObject)
    {
       thread1.Use(someGSObject);
    }
    lock(someObject)
    {
       thread2.Use(someGSObject);
    }
    
    0 讨论(0)
提交回复
热议问题