# Parallel execution

**URL:** <https://forum.kx.com/t/parallel-execution/8775>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [April 25, 2014, 11:54pm UTC](https://forum.kx.com/t/parallel-execution/8775 "2014-04-25T23:54:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zoya1](https://avatars.discourse-cdn.com/v4/letter/z/7ba0ec/32.png) [@Zoya1](https://forum.kx.com/u/Zoya1)\
**Post date:** [April 25, 2014, 11:54pm UTC](https://forum.kx.com/t/parallel-execution/8775/1 "2014-04-25T23:54:00Z")

</div>

&nbsp; Hello all,

&nbsp; I am wondering if Multithreaded Input Mode option is designed to allow the parallel execution of different requests.&nbsp; I start a long-running request, and would like to submit short-running requests in parallel, however after the long-running request starts, I am not able to submit to the server any other requests in parallel.&nbsp; My function calls are implemented in a loaded C library.

&nbsp; Thanks

---

<div class="post-metadata">

**Author:** ![\_Oz](https://avatars.discourse-cdn.com/v4/letter/_/f07891/32.png) [@\_Oz](https://forum.kx.com/u/_Oz)\
**Post date:** [April 29, 2014, 2:23pm UTC](https://forum.kx.com/t/parallel-execution/8775/2 "2014-04-29T14:23:00Z")

</div>

You should be able to open second connection from different thread and send request in parallel. Don’t forget to clean up ( r0 all k created and received in the thread and call m9() )&nbsp; before thread end, otherwise tls will leak

Cheers,  
Oleg

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [April 29, 2014, 2:33pm UTC](https://forum.kx.com/t/parallel-execution/8775/3 "2014-04-29T14:33:00Z")

</div>

new connections are accepted by the main thread,  
which runs when no other threads are currently executing a query.

So in this mode, open your connections early, and re-use them.

---

<div class="post-metadata">

**Author:** ![Sand\_m\_stone](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@Sand\_m\_stone](https://forum.kx.com/u/Sand_m_stone)\
**Post date:** [April 29, 2014, 5:04pm UTC](https://forum.kx.com/t/parallel-execution/8775/4 "2014-04-29T17:04:00Z")

</div>

So in other words, the query execution is still single-threaded even for select only queries? &nbsp;The doc&nbsp;http://code.kx.com/wiki/Cookbook/MultithreadedInputMode seems to indicate the select queries can be run concurrently, and it’s up to the users to ensure there is no mutation.&nbsp;

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [April 29, 2014, 5:09pm UTC](https://forum.kx.com/t/parallel-execution/8775/5 "2014-04-29T17:09:00Z")

</div>

no. In this mode queries run concurrently, each in their own thread.  
It is the accepting of new connections that requires currently executing queries to complete first. You can re-use a connection run another query.

These queries cannot change global data - it will throw an error to that thread if it tries.

The main thread can change globals. There’s a MWSR lock so all queries can run in read mode, but for the main thread to run, it must obtain the write lock.
