»Ë»Ñ Æ÷·³
°³¹ßÀÚÆ÷·³ ÀÔ´Ï´Ù.
  • ºÏ¸¶Å© ¾ÆÀÌÄÜ

C# SQLite db lock3

  • hhm
  • µî·ÏÀÏ 2015-02-06 11:28
  • Á¶È¸¼ö 627
C#
SQLite

ÇÑ class ¿¡´Ù insert, crate table µîµî db ÀÛ¾÷À» ÇÏ´Â ÇÔ¼ö¸¦ ¸¸µé¾î ³ù½À´Ï´Ù.
¼ö¸¹Àº class µéÀÌ À̳ÑÀ» »ý¼ºÇؼ­ »ç¿ëÇÏ°í ÀÖ¾î¿ä.
thread·Î ¼öÇàÀ» ÇÏ°Ô Çسù´Âµ¥ insert °¡ »¡¸® ³¡³ª´Â °æ¿ì¿¡´Â ±¦ÂúÀºµ¥ Çϳª°¡ ¿À·¡ °É¸®¸é ´Ù¸¥ thread ¿¡¼­ db lock ¿À·ù°¡ ³ª³×¿ä.
ÄÚµå´Â ´ëÃæ ¾Æ·¡¿Í °°½À´Ï´Ù.

class DB
{
        public insert1()
        {
                // ....
        }
}

class Thread1
{
        void Run()
        {
                Thread t = new Thread(ThreadFunc);
                t.Start();
        }

        ThreadFunc()
        {
                DB db = new DB();
                for(int a = 0; a < 1000; a++)<br />                 {
                        db.insert1();
                }
        }
}

class Thread2
{
        void Run()
        {
                Thread t = new Thread(ThreadFunc);
                t.Start();
        }

        ThreadFunc()
        {
                DB db = new DB();
                for(int a = 0; a < 1000; a++)<br />                 {
                        db.insert1();
                }
        }
}


±×·¡¼­ °Ë»öÀ» Á» Çغ¸°í lock À» ¾²¸é µÉ °Í °°¾Æ¼­ ÇغýÀ´Ï´Ù.
db ÀÛ¾÷ ÇÏ´Â class ¿¡´Ù°¡ ÀÌ·¸°Ô ÇÏ¸é µÇ´Â°Å ¾Æ´Ñ°¡¿ä?

class DB
{
        static object o = new object();
        public insert1()
        {
                lock(o)
                {
                        // ....
                }
        }
}

¾Æ´Ñ°¡º¸³×¿ä. ÀÌ·¸°Ô Çصµ lock exception ÀÌ ¹ß»ýÇÕ´Ï´Ù.

0
ÃßõÇϱ⠴ٸ¥ÀÇ°ß 0
|
°øÀ¯¹öÆ°

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ¼ú°ªÀº³»°¡³¾²²

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 Àϻ꺣¾î½º

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 hhm
  • ¾Ë¸² ¿å¼³, »óó ÁÙ ¼ö ÀÖ´Â ¾ÇÇÃÀº »ï°¡ÁÖ¼¼¿ä.
©¹æ »çÁø  
¡â ÀÌÀü±Û¡ä ´ÙÀ½±Û ¸ñ·Ïº¸±â