# Access to a ThreadPool's lock

**URL:** <https://forum.juce.com/t/access-to-a-threadpools-lock/4413>\
**Category:** General JUCE discussion\
**Created:** [October 19, 2009, 2:59pm UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413 "2009-10-19T14:59:50Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbyron](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@dbyron](https://forum.juce.com/u/dbyron)\
**Post date:** [October 19, 2009, 2:59pm UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413/1 "2009-10-19T14:59:50Z")

</div>

I’ve run into a situation where I’d like to look at, and potentially operate on all the jobs in a ThreadPool. It would be helpful to have access to the currently private ThreadPool::lock member. Would you consider either adding an accessor or making the member protected so I can create a child class with an accessor?

Thanks much.

-DB

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [October 20, 2009, 9:13am UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413/2 "2009-10-20T09:13:47Z")

</div>

I could make it protected, though it’s the sort of class that isn’t really supposed to be subclassed - its internal workings could change in future and break your code. What exactly are you trying to do? There might be something else I could add that would let you do what you need.

---

<div class="post-metadata">

**Author:** ![dbyron](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@dbyron](https://forum.juce.com/u/dbyron)\
**Post date:** [October 20, 2009, 2:40pm UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413/3 "2009-10-20T14:40:11Z")

</div>

I want to iterate through all the jobs in a ThreadPool and remove some of them. In this case, I’m using a subclass of ThreadPoolJob that has some other attribute I use to decide whether to remove or not.

So it’s similar to removeAllJobs but more like removeSomeJobs.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [October 21, 2009, 8:36am UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413/4 "2009-10-21T08:36:57Z")

</div>

Hmm, yes, that sort of thing gets very hairy in terms of thread-safety with all those jobs coming and going. Maybe a method that takes a callback function and calls it for each of the active jobs, asking whether that job should be deleted?

---

<div class="post-metadata">

**Author:** ![dbyron](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@dbyron](https://forum.juce.com/u/dbyron)\
**Post date:** [October 21, 2009, 3:18pm UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413/5 "2009-10-21T15:18:54Z")

</div>

I suppose some kind of callback would work but it feels way more complicated than making the member protected and allowing a child class to deal with it.

---

<div class="post-metadata">

**Author:** ![dbyron](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@dbyron](https://forum.juce.com/u/dbyron)\
**Post date:** [October 23, 2009, 12:52am UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413/6 "2009-10-23T00:52:10Z")

</div>

I think I changed my mind. The logic in ThreadPool::removeAllJobs is complicated enough that trying to get it right in a child class seems risky. A callback does seem better.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [October 23, 2009, 1:57pm UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413/7 "2009-10-23T13:57:38Z")

</div>

Yes, that was my thinking… It’s really a lot hairier than you’d expect.

---

<div class="post-metadata">

**Author:** ![dbyron](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@dbyron](https://forum.juce.com/u/dbyron)\
**Post date:** [October 26, 2009, 4:13am UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413/8 "2009-10-26T04:13:09Z")

</div>

Is it helpful if I come up with a patch?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [October 26, 2009, 1:21pm UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413/9 "2009-10-26T13:21:22Z")

</div>

Sure - that’d be really helpful!

---

<div class="post-metadata">

**Author:** ![dbyron](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@dbyron](https://forum.juce.com/u/dbyron)\
**Post date:** [December 1, 2009, 12:18am UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413/10 "2009-12-01T00:18:44Z")

</div>

At long last, I’ve got a patch – a git diff. I can’t figure out how to attach it to the post. All of the extensions I choose are “not allowed.” What’s the best way to get you the patch?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 1, 2009, 9:23am UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413/11 "2009-12-01T09:23:37Z")

</div>

Please don’t send me an actual patch file - I can’t stand messing about with them. I’d rather just compare your new file with my own version so I can easily see what the changes are.

---

<div class="post-metadata">

**Author:** ![dbyron](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@dbyron](https://forum.juce.com/u/dbyron)\
**Post date:** [December 1, 2009, 10:38am UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413/12 "2009-12-01T10:38:58Z")

</div>

I can send the whole file(s) (juce\_ThreadPool.h and juce\_ThreadPool.cpp). Should I just email them to you?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 1, 2009, 11:02am UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413/13 "2009-12-01T11:02:20Z")

</div>

Sure, send it over. Thanks!

---

<div class="post-metadata">

**Author:** ![dbyron](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@dbyron](https://forum.juce.com/u/dbyron)\
**Post date:** [December 1, 2009, 4:25pm UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413/14 "2009-12-01T16:25:29Z")

</div>

Sent.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 1, 2009, 5:37pm UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413/15 "2009-12-01T17:37:45Z")

</div>

Thanks, will take a look as soon as poss.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 9:49am UTC](https://forum.juce.com/t/access-to-a-threadpools-lock/4413/16 "2017-05-12T09:49:57Z")

</div>

Closed on May 12, 2017, 9:49am UTC


