# How to draw in Cinder concurrently?

**URL:** https://discourse.libcinder.org/t/how-to-draw-in-cinder-concurrently/1990
**Category:** Using Cinder
**Created:** [May 9, 2022, 2:05pm UTC](https://discourse.libcinder.org/t/how-to-draw-in-cinder-concurrently/1990 "2022-05-09T14:05:39Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![yomvol](https://avatars.discourse-cdn.com/v4/letter/y/b9bd4f/32.png) [@yomvol](https://discourse.libcinder.org/u/yomvol)
#### Post date: [May 9, 2022, 2:05pm UTC](https://discourse.libcinder.org/t/how-to-draw-in-cinder-concurrently/1990/1 "2022-05-09T14:05:39Z")

</div>

I`m trying to lauch 4 standart C++ threads, each drawing a line, but an abort() gets called in runtime. I try to adhere to [this example](https://github.com/cinder/Cinder/blob/master/samples/FlickrTestMultithreaded/src/FlickrTestMultithreadedApp.cpp), pass over the GL drawing context, use a mutex for thread synchronization. What do I do wrong?

```auto
void drawTest(gl::ContextRef _context, vec2 p1, vec2 p2, mutex& latch)
{
    ci::ThreadSetup threadSetup;
    latch.lock();
    _context->makeCurrent();
    gl::drawLine(p1, p2);
    latch.unlock();
}

void Func()
{
   vector<thread> threads;
   mutex myMutex;
   gl::ContextRef backgroundCtx = gl::Context::create(gl::context());
   threads.push_back(thread(drawTest, backgroundCtx, vec2(100, 344), vec2(150, 344), std::ref(myMutex)));
   threads.push_back(thread(drawTest, backgroundCtx, vec2(400, 850), vec2(730, 200), std::ref(myMutex)));
   threads.push_back(thread(drawTest, backgroundCtx, vec2(302, 540), vec2(150, 905), std::ref(myMutex)));
   threads.push_back(thread(drawTest, backgroundCtx, vec2(222, 930), vec2(50, 777), std::ref(myMutex)));
}

```

---

<div class="post-metadata">

### Author: ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)
#### Post date: [May 9, 2022, 2:11pm UTC](https://discourse.libcinder.org/t/how-to-draw-in-cinder-concurrently/1990/2 "2022-05-09T14:11:33Z")

</div>

Hi,

you’re not creating a separate context per thread. Each thread should have its own (shared) context.

There could be more problems with this code, but let’s first see what happens if you fix the first problem.

~Paul
