Question: I have a `socketChannel` (java.nio.channels.SocketChannel) listening for reading requests (from multiple clients). It stores each request in a **Request Queue**. 

Also `socketChannel.configureBlocking(false)`

Then I want the multiple threads to take one request at a time from the R**equest Queue** and write to the `socketChannel`

I have read the following from a documentation.

> 
> Socket channels are safe for use by multiple concurrent threads. They
>  support concurrent reading and writing, though at most one thread may
>  be reading and at most one thread may be writing at any given time.
> 
> 
> 

Since only 1 thread can be written, what can I do in the case of multiple writes?

Answer: 
Using magic numbers like this is fairly unmaintainable (adding new allowed times isn't clean, you have to edit conditions and such), your version with the array was better. The rest of this answer focuses on getting that solution to work how you wanted it to:

It's perfectly efficient (could make it more efficient by using a `std::set` or a `std::unordered_set`, but for such a small number of allowed values it's negligible), that's not an issue. Your current version is just as fast as the version with an array, as you still compare the same amount of numbers.

If your issue is that it prints the error 4 times, then keep a boolean flag to indicate the user's entered a valid value, and check it *after* the loop:

```
const unsigned int VALID_TIMES_SIZE = 4;
bool validTime = false;
for (unsigned int i = 0; i < VALID_TIMES_SIZE; ++i)
{
    if (ticket.screenTime == validTimes[i])
    {
        validTime = true;
        break;
    }
}
if (!validTime)
{
    printf("Invalid Screen Time! Enter again please!\n");
    // Redo the loop using continue, for example
}

```
To make something easy to understand you can avoid using those magic numbers or wrap them in a meaningful structure like `checkTime` and then use it for this kind of check. That way suppose next time you are asked to build a check time with some different times you won't have to look for hardcoded times and replace with it new things.

For example you can do something like this ,

```
struct checkTime{
  int *checkedTimes;
  int length;
  int (*checkIfTimeExists)(const struct checkTime* ch, int tm);
};
int checkTimerExistAux(const struct checkTime* ch,int tm)
{
    for(int i=0;i<ch->length;i++)
      if(ch->checktedTimes[i]==tm) return 1;
    return 0;
}

Then you create an `initilaize` function which will allocate memory and do this hardcoded thing. (like putting times and all that)[2,5,8,11] in your case.

initialize(); // here you created the structure `checkTimeInst`
// struct checkTime* checkTimeInstPtr = malloc(sizeof(struct checkTime));
// checkTimeInstPtr->checkedTimes = malloc(sizeof(int)*N);
// checkTimeInstPtr->length = 0;
// checkTimeInstPtr->checkIfTimeExists = checkTimerExistAux;
 do{
printf("Enter your screen time: ");
scanf("%d", &ticket.screenTime);

if(checkTimeInstPtr->checkIfTimeExists(checkTimeInstPtr,ticket.screenTime)==0){
    printf("Invalid Screen Time! Enter again please!\n");
}

} while(checkTimeInstPtr->checkIfTimeExists(checkTimeInstPtr,ticket.screenTime)==0);

```

---

This is not about speed up but it is about maintainability.

Here there is nothing that you can do about speed up. But yes if you are trying to squeeze time even more try to use the reader or scanner yourself using `getchar()` or similar. 

---

Initially the code posted assumed C++ where as OP asked for C language specific answer or modification. I have modified it to follow that criteria after **Paul Griffiths** comment.