Re: threads that won't yield

From: Frank Cusack (fcusack_at_fcusack.com)
Date: 06/17/03


Date: Mon, 16 Jun 2003 19:27:30 -0700

On 16 Jun 2003 19:45:00 -0400 Greg Menke <gregm-news@toadmail.com> wrote:
> Frank Cusack <fcusack@fcusack.com> writes:
>
>> [reposting, adding comp.programming.threads]
>>
>> Hi,
>>
>> In a simple pthreads app, I start a high priority thread and a low priority
>> thread, using SCHED_FIFO. The high pri thread runs first and blocks, then
>> the low priority thread runs and does a yield(), yet the high pri thread
>> does not start. Ugh. This works correctly (well, as I want it to) on Linux.
>> I'm running it as root, needed to set SCHED_FIFO I think.
>>
>>
>> The server thread sets up a unix domain socket and blocks on accept().
>> The client thread connect()s to that socket. (Don't ask) It's very
>> simple.
>>
>
> Does the connect() succeed?

Yes.

> If all you need to do is synchronize
> threads, you'll probably be better off using mutexes and the default
> scheduling algorithm.

How can I use a mutex when accept() must block?

  pthread_mutex_unlock(&m);
  /* client thread can run now */
  accept(...);

If the client thread starts running before accept() is called, won't
the connect() fail? Even if not (ie, listen() is enough to allow
connect() to succeed), I need a guarantee that the server thread runs
whenever it is runnable, which doesn't seem to be happening.

And more basically, I explicitly call sched_yield() in the client, this
does not start the server thread running. ugh.

/fc


Quantcast