UNIX Pipes

Can I use regular old pipes between the SDL threads?

To follow the path:
look to the master,
follow the master,
walk with the master,
see through the master,
become the master.---------------------------------
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing

Quoth Hudson T. Clark , on Fri 12 Dec 2003:

Can I use regular old pipes between the SDL threads?

I don’t believe so, no. This is a classic IPC problem. This is
generally done with a two-semaphore plus buffer combination, where the
semaphores keep track of how many chunks of data/space are available to
be read/written in the (usually cyclical) buffer – approximately as
follows:

Full-semaphore is inited to 0.
Empty-semaphore is inited to N.
Buffer has N blocks of data.
Read-pointer and write-pointer point to the beginning
of the buffer.

To read:
Decrement full-semaphore.
If there’s no data to read, this blocks.
Read one chunk from read-pointer.
Increment read-pointer by one chunk.
Wrap around at the end of the buffer.
Increment empty-semaphore.

To write:
Decrement empty-semaphore.
If there’s no room in the buffer, this blocks.
Write one chunk to write-pointer.
Increment write-pointer by one chunk.
Wrap around at the end of the buffer.
Increment full-semaphore.

HTH,
—> Drake Wilson
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20031216/2f614acd/attachment.pgp

Ok I understand it better now. I was looking at them but I didn’t understand them. Plus, it would be just nicer to me personally to use sockets. Do you or does anyone else know of some examples using this? I have been looking around the documentation, but maybe I missed the example if there is one. Your answer also brings another question, can I use internet sockets? I want to make the project I’m working on have the ability to use the network and TCP/IP.

Drake Wilson wrote:
Quoth Hudson T. Clark
, on Fri 12 Dec 2003:

Can I use regular old pipes between the SDL threads?

I don’t believe so, no. This is a classic IPC problem. This is
generally done with a two-semaphore plus buffer combination, where the
semaphores keep track of how many chunks of data/space are available to
be read/written in the (usually cyclical) buffer – approximately as
follows:

Full-semaphore is inited to 0.
Empty-semaphore is inited to N.
Buffer has N blocks of data.
Read-pointer and write-pointer point to the beginning
of the buffer.

To read:
Decrement full-semaphore.
If there’s no data to read, this blocks.
Read one chunk from read-pointer.
Increment read-pointer by one chunk.
Wrap around at the end of the buffer.
Increment empty-semaphore.

To write:
Decrement empty-semaphore.
If there’s no room in the buffer, this blocks.
Write one chunk to write-pointer.
Increment write-pointer by one chunk.
Wrap around at the end of the buffer.
Increment full-semaphore.

HTH,
—> Drake Wilson

ATTACHMENT part 2 application/pgp-signature

To follow the path:
look to the master,
follow the master,
walk with the master,
see through the master,
become the master.---------------------------------
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing

Check out SDL_Net!

http://www.libsdl.org/projects/SDL_net/----- Original Message -----
From: Hudson T. Clark
To: sdl at libsdl.org
Sent: Tuesday, December 16, 2003 11:43 AM
Subject: Re: [SDL] UNIX Pipes

Ok I understand it better now. I was looking at them but I didn’t understand them. Plus, it would be just nicer to me personally to use sockets. Do you or does anyone else know of some examples using this? I have been looking around the documentation, but maybe I missed the example if there is one. Your answer also brings another question, can I use internet sockets? I want to make the project I’m working on have the ability to use the network and TCP/IP.

Drake Wilson wrote:
Quoth Hudson T. Clark , on Fri 12 Dec 2003:
> Can I use regular old pipes between the SDL threads?

I don't believe so, no. This is a classic IPC problem. This is
generally done with a two-semaphore plus buffer combination, where the
semaphores keep track of how many chunks of data/space are available to
be read/written in the (usually cyclical) buffer -- approximately as
follows:

Full-semaphore is inited to 0.
Empty-semaphore is inited to N.
Buffer has N blocks of data.
Read-pointer and write-pointer point to the beginning
of the buffer.

To read:
Decrement full-semaphore.
If there's no data to read, this blocks.
Read one chunk from read-pointer.
Increment read-pointer by one chunk.
Wrap around at the end of the buffer.
Increment empty-semaphore.

To write:
Decrement empty-semaphore.
If there's no room in the buffer, this blocks.
Write one chunk to write-pointer.
Increment write-pointer by one chunk.
Wrap around at the end of the buffer.
Increment full-semaphore.

HTH,
---> Drake Wilson


> ATTACHMENT part 2 application/pgp-signature 

To follow the path:
look to the master,
follow the master,
walk with the master,
see through the master,
become the master.


Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing

I’m having problems understanding the semaphore’s documentation. What is in SDL_sem? I couldn’t find out what this datatype is. I have never used semaphore’s. Does anyone have example code in C to use them?

Alan Wolfe wrote:Check out SDL_Net!

http://www.libsdl.org/projects/SDL_net/> ----- Original Message -----

From: Hudson T. Clark
To: sdl at libsdl.org
Sent: Tuesday, December 16, 2003 11:43 AM
Subject: Re: [SDL] UNIX Pipes

Ok I understand it better now. I was looking at them but I didn’t understand them. Plus, it would be just nicer to me personally to use sockets. Do you or does anyone else know of some examples using this? I have been looking around the documentation, but maybe I missed the example if there is one. Your answer also brings another question, can I use internet sockets? I want to make the project I’m working on have the ability to use the network and TCP/IP.

Drake Wilson wrote:
Quoth Hudson T. Clark
, on Fri 12 Dec 2003:

Can I use regular old pipes between the SDL threads?

I don’t believe so, no. This is a classic IPC problem. This is
generally done with a two-semaphore plus buffer combination, where the
semaphores keep track of how many chunks of data/space are available to
be read/written in the (usually cyclical) buffer – approximately as
follows:

Full-semaphore is inited to 0.
Empty-semaphore is inited to N.
Buffer has N blocks of data.
Read-pointer and write-pointer point to the beginning
of the buffer.

To read:
Decrement full-semaphore.
If there’s no data to read, this blocks.
Read one chunk from read-pointer.
Increment read-pointer by one chunk.
Wrap around at the end of the buffer.
Increment empty-semaphore.

To write:
Decrement empty-semaphore.
If there’s no room in the buffer, this blocks.
Write one chunk to write-pointer.
Increment write-pointer by one chunk.
Wrap around at the end of the buffer.
Increment full-semaphore.

HTH,
—> Drake Wilson

ATTACHMENT part 2 application/pgp-signature

To follow the path:
look to the master,
follow the master,
walk with the master,
see through the master,
become the master.


Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing

To follow the path:
look to the master,
follow the master,
walk with the master,
see through the master,
become the master.


Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing

Hudson T. Clark , on Fri 12 Dec 2003:

Can I use regular old pipes between the SDL threads?

I have used a pipe between SDL threads on a Linux 2.4.x kernel
with SDL 1.2.4 and it seemed to work OK. I have certainly
used a pipe between pthreads on Linux 2.4.x kernel (not with NPTL).

I don’t know what it would be about SDL threads that would preclude
using a pipe.

Hudson T. Clark , on Fri 12 Dec 2003:

Can I use regular old pipes between the SDL threads?

I have used a pipe between SDL threads on a Linux 2.4.x kernel
with SDL 1.2.4 and it seemed to work OK. I have certainly
used a pipe between pthreads on Linux 2.4.x kernel (not with NPTL).

I don’t know what it would be about SDL threads that would preclude
using a pipe.

I’ve used pipes between threads as well (posix threads in this case).

I used them to signal a thread that was multiplexing over mulitple
TCP connections (using poll), that outbound data was ready to
be sent.

I didn’t see any problems and am kinda curious as to why a previous
poster said not to use them (and use an IPC solution).

Daryl

p.s. I suspect the IPC solution (of counting semaphores) is alot faster
than a pipe … but was there another reason?

Err, of course you can. It’s not the most efficient thing to do (moving
data through a kernel buffer when you’re already in the same memory space),
or the most portable (if you want to work on archs that don’t have pipes),
but it should certainly work (with no extra mutexes or semaphores).

You can use pipes to make a process communicate with itself, eg.

int fd[2];
pipe(fd);
write(fd[1], buf, size);
read(fd[0], buf, size);

and it works just as well if you’re reading in a different thread.

If you want two-directional comms, you’ll need either two pipes or a
socketpair, of course.On Fri, Dec 12, 2003 at 04:30:00AM -0500, Drake Wilson wrote:

Can I use regular old pipes between the SDL threads?

I don’t believe so, no. This is a classic IPC problem. This is


Glenn Maynard

I don’t know what it would be about SDL threads that would preclude
using a pipe.

Yeah. Thats kind of what I was thinking.

Douglas Jerome wrote:

Hudson T. Clark
, on Fri 12 Dec 2003:

Can I use regular old pipes between the SDL threads?

I have used a pipe between SDL threads on a Linux 2.4.x kernel
with SDL 1.2.4 and it seemed to work OK. I have certainly
used a pipe between pthreads on Linux 2.4.x kernel (not with NPTL).

I don’t know what it would be about SDL threads that would preclude
using a pipe._______________________________________________
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

To follow the path:
look to the master,
follow the master,
walk with the master,
see through the master,
become the master.


Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing

Well I don’t understand how to use semaphores, and I thought that pipes or IPC sockets would be better (no paticular reason just what I would prefer?). I’m making a gui system for an isometric engine. I have text routines working, and now I’m playing with making some buttons. I have to start working on the isometric engine. But I do have a checkers game I have been also playing around with. I’m thinking about using it to test out my gui. But I need however threaded GUI stuff. For example I need to be able to drop all interactive gui things (buttons, text entry, etc) into a thread, and have them communicate back with a main thread that controls user I/O (bidirectional communication).

Daryl Lonnon wrote:

Hudson T. Clark
, on Fri 12 Dec 2003:

Can I use regular old pipes between the SDL threads?

I have used a pipe between SDL threads on a Linux 2.4.x kernel
with SDL 1.2.4 and it seemed to work OK. I have certainly
used a pipe between pthreads on Linux 2.4.x kernel (not with NPTL).

I don’t know what it would be about SDL threads that would preclude
using a pipe.

I’ve used pipes between threads as well (posix threads in this case).

I used them to signal a thread that was multiplexing over mulitple
TCP connections (using poll), that outbound data was ready to
be sent.

I didn’t see any problems and am kinda curious as to why a previous
poster said not to use them (and use an IPC solution).

Daryl

p.s. I suspect the IPC solution (of counting semaphores) is alot faster
than a pipe … but was there another reason?_______________________________________________
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

To follow the path:
look to the master,
follow the master,
walk with the master,
see through the master,
become the master.


Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing

Alright thanks for the ideas! I didn’t think there would be a problem and I didn’t understand why there would be…? Thank you.

Glenn Maynard <g_sdl at zewt.org> wrote:On Fri, Dec 12, 2003 at 04:30:00AM -0500, Drake Wilson wrote:

Can I use regular old pipes between the SDL threads?

I don’t believe so, no. This is a classic IPC problem. This is

Err, of course you can. It’s not the most efficient thing to do (moving
data through a kernel buffer when you’re already in the same memory space),
or the most portable (if you want to work on archs that don’t have pipes),
but it should certainly work (with no extra mutexes or semaphores).

You can use pipes to make a process communicate with itself, eg.

int fd[2];
pipe(fd);
write(fd[1], buf, size);
read(fd[0], buf, size);

and it works just as well if you’re reading in a different thread.

If you want two-directional comms, you’ll need either two pipes or a
socketpair, of course.–
Glenn Maynard


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

To follow the path:
look to the master,
follow the master,
walk with the master,
see through the master,
become the master.


Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing

Hudson T. Clark wrote:

Well I don’t understand how to use semaphores, and I thought that pipes
or IPC sockets would be better (no paticular reason just what I would
prefer?). I’m making a gui system for an isometric engine. I have text
routines working, and now I’m playing with making some buttons. I have
to start working on the isometric engine. But I do have a checkers game
I have been also playing around with. I’m thinking about using it to
test out my gui. But I need however threaded GUI stuff. For example I
need to be able to drop all interactive gui things (buttons, text entry,
etc) into a thread, and have them communicate back with a main thread
that controls user I/O (bidirectional communication).

This is relatively confusing: “interactive gui things” are “user I/O”.

SDL_SetVideoMode() returns a pointer to an SDL surface; make sure that
all operations on that surface are in the same thread. There may be
other things that need to be in the same thread, but I am not clear as
to what they are.> /Daryl Lonnon / wrote:

 > Hudson T. Clark , on Fri 12 Dec 2003:
 > >
 > >Can I use regular old pipes between the SDL threads?
 >
 > I have used a pipe between SDL threads on a Linux 2.4.x kernel
 > with SDL 1.2.4 and it seemed to work OK. I have certainly
 > used a pipe between pthreads on Linux 2.4.x kernel (not with NPTL).
 >
 > I don't know what it would be about SDL threads that would preclude
 > using a pipe.

I've used pipes between threads as well (posix threads in this case).

I used them to signal a thread that was multiplexing over mulitple
TCP connections (using poll), that outbound data was ready to
be sent.

I didn't see any problems and am kinda curious as to why a previous
poster said not to use them (and use an IPC solution).

Daryl

p.s. I suspect the IPC solut! ion (of counting semaphores) is alot
faster
than a pipe ... but was there another reason?

_______________________________________________
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

To follow the path:
look to the master,
follow the master,
walk with the master,
see through the master,
become the master.


Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing
http://pa.yahoo.com/*http://us.rd.yahoo.com/evt=21260/*http://photos.yahoo.com

test out my gui. But I need however threaded GUI stuff. For example I
need to be able to drop all interactive gui things (buttons, text entry,
etc) into a thread, and have them communicate back with a main thread
that controls user I/O (bidirectional communication).

Sounds like a class assignment to me. :slight_smile: I’d very rarely consider
threading like this in real life, and I’ve always hated how people tend
to come out of classes having learned how to use threads but having no
concept of when they’re really appropriate (and then use the gun they’ve
been given to shoot other people in the foot) …

SDL_SetVideoMode() returns a pointer to an SDL surface; make sure that
all operations on that surface are in the same thread. There may be
other things that need to be in the same thread, but I am not clear as
to what they are.

To clarify: are in the same thread as the call to SDL_SetVideoMode.On Tue, Dec 16, 2003 at 02:52:07PM -0700, Douglas Jerome wrote:


Glenn Maynard

Well I need to come up with a way to check a very simlpe gui system. I was thinking about having like a “canvas” structure, and it would have all the buttons, text entries, labels, etc… I don’t know. I just thought maybe the best thing would be to check all this is a single process. But then when I found anything that would require anymore computing then checking I could throw it off into its own process? Like if a button was pressed a thread would go off and run any callback routine? I was thinking to fix the problem of only one thread or process can use a specific SDL_Surface, maybe the best thing would be to communicate with a drawing thread? If anyone has any brain storm ideas please share.

Glenn Maynard <g_sdl at zewt.org> wrote:On Tue, Dec 16, 2003 at 02:52:07PM -0700, Douglas Jerome wrote:

test out my gui. But I need however threaded GUI stuff. For example I
need to be able to drop all interactive gui things (buttons, text entry,
etc) into a thread, and have them communicate back with a main thread
that controls user I/O (bidirectional communication).

Sounds like a class assignment to me. :slight_smile: I’d very rarely consider
threading like this in real life, and I’ve always hated how people tend
to come out of classes having learned how to use threads but having no
concept of when they’re really appropriate (and then use the gun they’ve
been given to shoot other people in the foot) …

SDL_SetVideoMode() returns a pointer to an SDL surface; make sure that
all operations on that surface are in the same thread. There may be
other things that need to be in the same thread, but I am not clear as
to what they are.

To clarify: are in the same thread as the call to SDL_SetVideoMode.–
Glenn Maynard


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

To follow the path:
look to the master,
follow the master,
walk with the master,
see through the master,
become the master.


Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing

Quoth Glenn Maynard <g_sdl at zewt.org>, on Fri 12 Dec 2003:

You can use pipes to make a process communicate with itself, eg.

int fd[2];
pipe(fd);
write(fd[1], buf, size);
read(fd[0], buf, size);

and it works just as well if you’re reading in a different thread.

I fall corrected! fwump

I think I was thinking of two processes trying to use the same pipe
bidirectionally, which doesn’t work – but also isn’t this situation,
so it’s completely irrelevant. Mea culpa.

It is still in my opinion better to do it with a buffer if it’s
convenient and it’s inside the same address space (which for threads
within a process it is), but native kernelish pipes should work, yes.

Thank you for your correction.

—> Drake Wilson
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20031216/e6f4aa34/attachment.pgp