# When to call SDL\_CondSignal()

**URL:** <https://discourse.libsdl.org/t/when-to-call-sdl-condsignal/14016>\
**Category:** SDL Development\
**Created:** [November 13, 2006, 4:51am UTC](https://discourse.libsdl.org/t/when-to-call-sdl-condsignal/14016 "2006-11-13T04:51:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lazy\_Foo](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/a9a28c/32.png) [@Lazy\_Foo](https://discourse.libsdl.org/u/Lazy_Foo)\
**Post date:** [November 13, 2006, 4:51am UTC](https://discourse.libsdl.org/t/when-to-call-sdl-condsignal/14016/1 "2006-11-13T04:51:54Z")

</div>

I’m redoing the producer/consumer example in SDL.

Here are my produce() and consume() functions:

void produce()  
{  
//Lock  
SDL\_mutexP( bufferLock );

```
//If the buffer is full
if( buffer != NULL )
{
    //Wait for buffer to be cleared
    SDL_CondWait( canProduce, bufferLock );
}

//Fill buffer
buffer = images[rand() % 5];

//Signal consumer
SDL_CondSignal( canConsume );

//Unlock
SDL_mutexV( bufferLock );

```

}

void consume()  
{  
//Lock  
SDL\_mutexP( bufferLock );

```
//If the buffer is empty
if( buffer == NULL )
{
    //Wait for buffer to be filled
    SDL_CondWait( canConsume, bufferLock );
}

//Empty buffer
buffer = NULL;

//Signal producer
SDL_CondSignal( canProduce );

//Unlock
SDL_mutexV( bufferLock );

```

}

I just want to make sure I’m supposed to call SDL\_CondSignal() to signal the  
other thread before or after calling SDL\_mutexV() to unlock the mutex.

So am I doing this right?
