Berkeley DB Reference Guide:
Programmer Notes

PrevRefNext

Multithreaded applications

Berkeley DB fully supports multithreaded applications. The Berkeley DB library is not itself multithreaded, and was deliberately architected to not use threads internally because of the portability problems that would introduce. Database environment and database object handles returned from Berkeley DB library functions are free-threaded. No other object handles returned from the Berkeley DB library are free-threaded. The following rules should be observed when using threads to access the Berkeley DB library:

(¹öŬ¸® µðºñ´Â ³»ºÎÀûÀ¸·Î ¾²·¡µå¸¦ »ç¿ëÇÏÁö ¾Ê´Â´Ù.Æ÷Æà ¹®Á¦ ¶§¹®ÀÌ´Ù.¶óÀ̺귯¸® ÇÔ¼ö¿¡¼­ ¸®ÅÏµÈ µðºñ ȯ°æ°ú µðºñ¿ÀºêÁ§Æ®´Â ¾²·¹µå¿¡ ÀÚÀ¯·Ó°í ±×¿Ü´Â ÀÚÀ¯·ÓÁö ¾Ê´Ù. ¾²·¹µå·Î ¶óÀ̺귯¸®¸¦ Á¢±ÙÇÒ¶§ ´ÙÀ½ÀÇ ·êÀ» µû¸£±â ¹Ù¶õ´Ù.)

¡¡

  1. The DB_THREAD flag must be specified to the DB_ENV->open and DB->open methods if the Berkeley DB handles returned by those interfaces will be used in the context of more than one thread. Setting the DB_THREAD flag inconsistently may result in database corruption.

    ( DB_ENV->open , DB->open ¿¡ DB_THREAD Ç÷¡±×¸¦ ¼³Á¤ÇØ¾ß ÇÑ´Ù. )

    Threading is assumed in the Java API, so no special flags are required; and Berkeley DB functions will always behave as if the DB_THREAD flag was specified.

    Only a single thread may call the DB_ENV->close or DB->close methods for a returned environment or database handle.

    (¿ÀÁ÷ ÇϳªÀÇ ¾²·¹µå¸¸ÀÌ DB_ENV->close or DB->close¸¦ È£Ãâ.)

    No other Berkeley DB handles are free-threaded.

    (´Ù¸¥ ÇÚµéÀº ¾²·¹µå¿¡ ÀÚÀ¯·ÓÁö ¸øÇÏ´Ù.)

    ¡¡

  2. When using the non-cursor Berkeley DB calls to retrieve key/data items (for example, DB->get), the memory to which the pointer stored into the Dbt refers is valid only until the next call using the DB handle returned by DB->open. This includes any use of the returned DB handle, including by another thread within the process.

    (Ä¿¼­¸¦ »ç¿ëÇÏÁö ¾Ê°í Å°/µ¥ÀÌŸ ¸¦ ÀÐÀ»¶§ DBT¿¡ ÀúÀåµÈ Æ÷ÀÎÅÍ´Â DBÇÚµéÀ» »ç¿ëÇÏ´Â ´ÙÀ½ ÇÔ¼öÄݱîÁö À¯È¿ÇÏ´Ù.ÀÌ ÇÔ¼öÄÝÀº ¾²·¹µåµé¿¡ ÀÇÇØ È£ÃâµÉ¶§µµ ¸¶Âù°¡Áö´Ù.)

    For this reason, if the DB_THREAD handle was specified to the DB->open method, either DB_DBT_MALLOC, DB_DBT_REALLOC, or DB_DBT_USERMEM must be specified in the DBT when performing any non-cursor key or data retrieval.

    (ÀÌ°°Àº ÀÌÀ¯·Î  DB->open¿¡ DB_THREAD¸¦ ¼³Á¤Çß´Ù¸é ³ÍÄ¿¼­ Å°/µ¥ÀÌŸ Àб⿡¼­´Â DB_DBT_MALLOC, DB_DBT_REALLOC, or DB_DBT_USERMEM°¡ DBT¿¡ ¼³Á¤µÇ¾î¾ß ÇÑ´Ù.)

    ¡¡

  3. Cursors may not span transactions. Each cursor must be allocated and deallocated within the same transaction.

    (Ä¿¼­´Â Æ®·£Á§¼Çµé »çÀÌ¿¡¼­ È®ÀåµÇ¾î Àû¿ëµÇÁö ¾Ê´Â´Ù.°¢ Ä¿¼­´Â °°Àº Æ®·£Á§¼Ç¿¡¼­ È°´ç,ºñÈ°´ç µÇ¾î¾ß ÇÑ´Ù.)

    Transactions and cursors may span threads, but only serially, that is, the application must serialize access to the DB_TXN and DBC handles. In the case of nested transactions, since all child transactions are part of the same parent transaction, they must observe the same constraints. That is, children may execute in different threads only if each child executes serially.

    (Æ®·£Á§¼Ç°ú Ä¿¼­´Â ¾²·¹µåµé »çÀÌ¿¡¼­ È®ÀåµÇ¾î Àû¿ëµÉ ¼ö ÀÖ´Ù.±×·¯³ª ¿ÀÁ÷ ½Ã¸®¾óÀûÀ¸·Î µ¿ÀÛÇØ¾ß ÇÑ´Ù.Áï ¾ÖÇø®ÄÉÀ̼ÇÀº DB_TXN and DBC handlesÀ» ¼øÂ÷ÀûÀ¸·Î Á¢±ÙÇØ¾ß ÇÑ´Ù.³»Æ÷µÈ ÇÁ·£Á§¼ÇÀÇ °æ¿ì ¸ðµç ÀÚ½Ä Æ®·£Á§¼ÇÀº ÇϳªÀÇ °°Àº ºÎ¸ð Æ®·£Á§¼ÇÀÇ ÀϺκÐÀÌ´Ù.¶ÇÇÑ À̵éÀº °°Àº Á¦¾àÁ¶°ÇÀ» ÁؼöÇÏ°Ô µÈ´Ù.Áï ÀÚ½ÄÆ®·£Á§¼ÇÀº °¢ ÀÚ½ÄÀÌ ½Ã¸®¾óÀûÀ¸·Î ¿ÀÁ÷ ½ÇÇàµÉ¶§¸¸ÀÌ ¿©·¯ ´Ù¸¥ ¾²·¹µå¿¡¼­ ½ÇÇà°¡´ÉÇÏ´Ù.)

    ¡¡

  4. User-level synchronization mutexes must have been implemented for the compiler/architecture combination. Attempting to specify the DB_THREAD flag will fail if fast mutexes are not available.

    (»ç¿ëÀÚ ·¹º§ µ¿±âÈ­ ¹ÂÅؽº´Â ÄÄÆÄÀÏ·¯/¾ÆÅ°ÅØÃÄ Á¶ÇÕ¿¡ ÀÇÇØ ±¸ÇöµÇ¾î¾ß ÇÑ´Ù.¸¸¾à ºü¸¥ ¹ÂÅؽº°¡ »ç¿ë°¡´ÉÇÏÁö ¾Ê´Ù¸é  DB_THREADÇ÷¡±×ÀÇ ¼³Á¤Àº ½ÇÆÐÇÏ°Ô µÈ´Ù.)

     

    If blocking mutexes are available (for example POSIX pthreads), they will be used. Otherwise, the Berkeley DB library will make a system call to pause for some amount of time when it is necessary to wait on a lock. This may not be optimal, especially in a thread-only environment, in which it is usually more efficient to explicitly yield the processor to another thread.

    (¸¸¾à ºí·°Å· ¹ÂÅؽº°¡ »ç¿ë°¡´ÉÇϸé ÀÌ°ÍÀÌ »ç¿ëµÈ´Ù.±×·¸Áö ¾ÊÀ¸¸é ¶ôÀÌ ÇÊ¿äÇÒ¶§ ÀÏÁ¤½Ã°£µ¿¾È Á¤ÁöÇÏ´Â ½Ã½ºÅÛÄÝÀ» È£ÃâÇÏ°Ô µÈ´Ù.)

    ¡¡

    It is possible to specify a yield function on an per-application basis. See db_env_set_func_yield for more information.

    (¾ÖÇø®ÄÉÀ̼Ǻ£À̽ºÀÇ yieldÇÔ¼ö¸¦ ¼³Á¤ÇÒ¼ö ÀÖ´Ù. db_env_set_func_yieldÂüÁ¶)

    It is possible to specify the number of attempts that will be made to acquire the mutex before waiting. See DB_ENV->set_tas_spins for more information.
    (´ë±âÀü¿¡ ¹ÂÅؽº¸¦ ¾ò±âÀ§ÇÑ ½ÃµµÈ½¼ö¸¦ ¼³Á¤ÇÒ¼ö ÀÖ´Ù. DB_ENV->set_tas_spins ÂüÁ¶)

When creating multiple databases in a single physical file, multithreaded programs may have additional requirements. For more information, see Opening multiple databases in a single file.

(´ÜÀÏ ¹°¸®Àû ÆÄÀÏ¿¡ ¸ÖƼ µðºñ¸¦ »ý¼ºÇÒ¶§ ¸ÖƼ¾²·¹µå ÇÁ·Î±×·¥Àº Ãß°¡ÀûÀ¸·Î ÁؼöÇØ¾ß ÇÒ°Ô ÀÖ´Ù. Opening multiple databases in a single file.ÂüÁ¶)


PrevRefNext

Copyright (c) 1996-2003 Sleepycat Software, Inc. - All rights reserved.