Re: [hawtdispatch] Details about hawtdispatch threading internals

74 views
Skip to first unread message

Hiram Chirino

unread,
Jun 28, 2012, 10:14:05 PM6/28/12
to hawtdi...@googlegroups.com
HI Christianm

On Thu, Jun 28, 2012 at 6:28 PM, christian.posta <christi...@gmail.com> wrote:

looking for quick clarification.. in hawtdispatch.. all of the threads in the SimplePool are basically "parked" if there are no tasks in the three queues to process (local, shared, source). it parks by calling select(-1) which will block/wait until there is either activity on the selection channels or wakeup() is called on the selector…


Correct.
 

looks like in SimplePool, when a task is added, the threads in the pool are looped and asked to wakeup if they're parked?

Well, it wakes up at most 1 thread.

if there's a task added to the queue, and a thread is asked to "wakeup" what happens if a selection event occurs right when it's processing the task? ie, it's not currently selecting… does it process all tasks in the queue first, then work on the selection?

Correct, it drains all the work tasks before asking the selector of there are any selection events that need to processed.  IO state changes in effect are queued on the selector.  Once all processing queues are drained, then we hit the selector for and if there were queued IO events, then the selector pop out without blocking and we process those IO events by triggering the corresponding DispatchSource tasks.

also, can you shed some light on the wakeUpCounter and the selectCounter and how they're related in the NioManager? sorry for all of the questions.. think im on the right track, just need some confirmation.

The wakeUpCounter and the selectCounter are used to avoid doing unnecessary Selector.wakeup() and Selector.select() calls which can be expensive.
They track if another thread had requested a wakeup, and if so avoid doing a blocking select so that the processing queues can get drained.  And similarly, they can be used to know if the thread is really currently doing a blocking select, and if not, then avoid doing the wakeup.

--

Hiram Chirino

Software Fellow | FuseSource Corp.

chi...@fusesource.com | fusesource.com

skype: hiramchirino | twitter: @hiramchirino

blog: Hiram Chirino's Bit Mojo




christian.posta

unread,
Jun 29, 2012, 12:31:11 AM6/29/12
to hawtdi...@googlegroups.com
Awesome, thanks for this helpful info.


On Thursday, June 28, 2012 3:28:08 PM UTC-7, christian.posta wrote:

looking for quick clarification.. in hawtdispatch.. all of the threads in the SimplePool are basically "parked" if there are no tasks in the three queues to process (local, shared, source). it parks by calling select(-1) which will block/wait until there is either activity on the selection channels or wakeup() is called on the selector…

looks like in SimplePool, when a task is added, the threads in the pool are looped and asked to wakeup if they're parked?

if there's a task added to the queue, and a thread is asked to "wakeup" what happens if a selection event occurs right when it's processing the task? ie, it's not currently selecting… does it process all tasks in the queue first, then work on the selection?

also, can you shed some light on the wakeUpCounter and the selectCounter and how they're related in the NioManager? sorry for all of the questions.. think im on the right track, just need some confirmation.

Reply all
Reply to author
Forward
0 new messages