Signals and semaphores

I know I can do it like you suggested but I have more complicated case. I will try to explain my application more clearly.

I building communication gateway that connects two industrial networks (I have two network interfaces). I have two important threads. First thread is listening on Ethernet port 0 (eth0). This thread is basically a infinite loop that accepts incoming connections and messages send via GPRS protocol. When new message is received, it is processed by another thread. This new thread writes log files (for example) .

Second thread is listening on eth1. In most parts it is basically the same as first thread, but it can have just one client and another protocol is implemented.
Same as in first thread, when new message is received, it is processed by another thread. When message is received, response is send back right away
and my counter (they are counting from zero to timeout value) are reset.

If there is no new messages (timeout occurs) new thread is open (now from main program, before from signal handler) and message (required by protocol)
is send by another thread.

I have few variables that are shared between threads and main program. Counter is just one of them. Counter is different because it is incremented every second.

Before joining this forum I had sem_wait() before variable increment/decrement/reinitialization operation which was followed by sem_post(). I didn't put
semaphores if I was just testing logical expression. I've changed that.

I'm thinking of doing sem_post inside signal handler and sem_wait inside infitine while loop inside main(). This way code inside infinite loop will run once in
a second and tick variable will be threadsafe. All other shared variables will have sem_wait() -> operation -> sem_post(). Is this ok? I've attached below new pseudo code.

thread1() 
{
         sem_wait(semCounter)
         if(new_message_recieved)
               counter.t1 = 0;
         sem_post(semCounter);
}
 
void timer_handler(int signum) 
{     
       // counters are removed from signal_handler
       sem_post(semTick); 
}

int main()
{
      // Start timer
      // start main threads

      while(1)
      {
             
            sem_wait(semTick);
            // code bellow will be executed once in a second
            sem_wait(semCounter);
            counter.t1++;
            sem_post(semCounter);
       }
}

One more question about checking error code. If my sem_wait() is interruped by signal, it will return EINTR regardles of SA_RESTART flag. This way I could execute sem_wait() two times and sem_post just once.