Re: Events

From: Christopher Thompson (chris@hypocrite.org)
Date: Thu Jun 22 2000 - 18:18:03 EST


I must admit to two things:
First, I'm not particularly well-versed with multithreaded
programming.
Second, I'm not totally sure I understand what you are trying to
do.

However, it strikes me that perhaps what you want to look into
is shared memory and semaphores, or perhaps message queues.
Someone else can describe message queues to you.

Shared memory basically allows you to share a chunk of memory.
You protect access to this chunk by using a semaphore.
Depending on how you use the semaphore, you may also need to use
a single signal to inform the other process that it has a
message waiting inside the shared memory.

Then in your signal handler, or whatever other method you use to
determine you have a message waiting, you grab it out of shared
memroy and dispatch it.

This way, you have *ONE* small chunk of shared memory, *ONE*
semaphore, and must catch at most ONE signal. :)

(Please email me privately if you want a little more info than
this.)

On Thu, 22 Jun 2000, you wrote:
> My problem is I cannot find a way to make a clear event
> handling under Linux. Let me explain
>
> For example we have a thread, this thread handle the file
> IO. When I'm wating for some data I can use the select
> function to check it out if there is anything for me. If I
> want to stop the thread during the select, I have no other
> way except for the signal handlers functions.
> It is not really handy, because the example above is too
> simple. In our case is much more difficulter.
>
> At the moment as we saw in an example on the Net, we are
> creating pipes for the events. And we just write one single
> byte into the pipe to make it signaled and delete it from
> the buffer to make it unsignaled.
> It is not a nice way, either, but works. Unfortunatelly we
> need about 10,000 events. If I used the pipes for the
> events, I would need about 20,000 file descriptor.
>
> We made a test system with about 8000 file descriptor. It
> worked fine when we rebuilt the Kernel. The only problem the
> Linux is too good to make this kind of stupid programs.
>
> I've taken a look to the Kernel. And I think we could make a
> new type of file descriptor only for events.
>
> Example:
> This example just try to expalin how I tend to use the new
> function. It's syntax is not correct
>
> int i = open(....);
> int j = event(.....);
>
> switch( poll( 2, i, j))
> {
> case i:
> // file event;
> break;
> case j:
> // event signaled by somebody
> break;
> ...
>
>
> I've also check out the pthread library, but I couldn't find
> usefull the implementation of the events in the pthread.
> I think this kind of stuff should be in the Kernel.
>
> My question if anybody have the same problem before and you
> think it is going to be fine??
> I'm going to make a patch for us. If anybody interesting in
> it, I would be appreciated for any kind of help.
>
> Have a very good day for all of you:-)
>
> Yuri
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.rutgers.edu
> Please read the FAQ at http://www.tux.org/lkml/

-- 
Christopher Thompson  http://hypocrite.org/
"I wish I were a glow worm/A glow worm's never glum
Cos how can you be grumpy/When the sun shines out your bum?"

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri Jun 23 2000 - 21:00:25 EST