SerialDispatchQueue why need two queues(externalQueue and localQueue)?

20 views
Skip to first unread message

张伟

unread,
Jun 25, 2013, 5:31:20 AM6/25/13
to hawtdi...@googlegroups.com
  I read SerialDispatchQueue source code, and I find that there are two task queues in it. Why two queues? And why two queues have difffrent type: ConcurrentLinkedQueue and LinkedList?


Hiram Chirino

unread,
Jun 25, 2013, 9:37:05 AM6/25/13
to hawtdispatch
It's an optimization for when you add more tasks to the dispatch queue
which is currently executing on the current thread. Adding to the
non-thread safe LinkedList is much faster than adding to the
ConcurrentLinkedQueue.
> --
> You received this message because you are subscribed to the Google Groups
> "hawtdispatch" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to hawtdispatch...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Hiram Chirino

Engineering | Red Hat, Inc.

hchi...@redhat.com | fusesource.com | redhat.com

skype: hiramchirino | twitter: @hiramchirino

blog: Hiram Chirino's Bit Mojo

Christian Posta

unread,
Jun 25, 2013, 9:44:57 AM6/25/13
to hawtdi...@googlegroups.com
Hiram,
What happens when a serial dispatch queue is executing on a global queue thread but a different global queue thread tries to enqueue to the serial dispatch queue, or some non hawtdispatch thread tries enqueue to that serial dispatch queue... Seems the non thread safe data structure is still used? Or is that "is executing" guard in the enqueue method specific to "is executing on current thread"?


--
Christian Posta
twitter: @christianposta

Hiram Chirino

unread,
Jun 25, 2013, 11:05:02 AM6/25/13
to hawtdispatch
Yes. The "is executing" guard is specific to "is executing on current thread".
Reply all
Reply to author
Forward
0 new messages