Opened 7 years ago

Last modified 7 years ago

#1616 closed enhancement

Group lock and other foundation in PJLIB for fixing synchronization issues — at Version 1

Reported by: bennylp Owned by: bennylp
Priority: normal Milestone: release-2.1
Component: pjlib Version: trunk
Keywords: Cc:
Backport to 1.x milestone: Backported: no

Description (last modified by bennylp)

This ticket contains works done in PJLIB which lay foundation for fixing various synchronization issue in upper layer such as PJNATH. The detail of the work is as follows.

Group Lock

Implement Group Lock, a new synchronization object for dealing with deadlock and session management. Please see the link for more info.

More robust timer heap

  • Integration of group lock to the timer heap. A new API is introduced: pj_timer_heap_schedule_w_grp_lock(), which adds reference counter to the group lock when timer is scheduled, and automatically decrements it after the timer expires or cancelled, to prevent the group lock from being destroyed when a timer callback is about to be executed. This API also sets the timer "id" automatically and atomically.
  • New convenience API: pj_timer_heap_cancel_if_active() to cancel a timer without having to firstly check if it is active or not.

Changes is ioqueue and active socket

  • Ioqueue key to use lock object instead of mutex. This is required so that the lock can be synchronized with the group lock. The ioqueue key's lock can be retrieved from the active socket as well.
  • Added pj_activesock_shutdown() to cancel all pending operations. It is now recommended that active socket closure is done in two stages (shutdown and then destroy) to avoid race condition where the object is destroyed while callback is about to execute.


  • New PJ_EGONE error code. It is used when pj_grp_lock_dec_ref() or pj_grp_lock_release() causes the group lock to be destroyed.
  • New PJ_RACE_ME(x) macro which can be inserted in various strategic locations. During testing, the macro can be replaced with pj_thread_sleep(x) in order to trigger race condition to happen.
  • Event object (similar to Windows event) implementation for os_core_unix.c based on Pthread condition variable. This is used by the pjnath-test testing program to synchronize the tests.

Change History (1)

comment:1 Changed 7 years ago by bennylp

  • Description modified (diff)
Note: See TracTickets for help on using tickets.