Are events thread safe?

Are events thread safe when placed on the queue with SDL_PushThread()
in SDL-1.1.5?

I see that this question was asked by Giulio Euliss on Oct 29th with
no response. I was looking to see if it was safe for me to free the
memory for an SDL_Event that I’ve allocated. All of the samples
I’ve found in the source create Events on the stack in tight loops
and provide SDL_PushEvent with a pointer to the event, i.e.

( from events/SDL_resize.c )
{
SDL_Event e;
e.type = SDL_VIDEORESIZE;
SDL_PushEvent(&e);
}

However, SDL_PushEvent merely calls SDL_PeepEvents with an SDL_ADDEVENT
flag, which calls SDL_AddEvent(). SDL_AddEvent adds MY pointer
to the event queue. ( All of this code is in events/SDL_events.c. )

I’m worried about this. Since the event goes out of scope as soon
as PushEvent is called in the above example from SDL_resize.c, how
am I assured that the pointer still references valid data when the
queue is read? I would think that SDL_PushEvent() would need to copy
the event data.

Of course, it is likely that I don’t understand something. I’ve never
actually had a problem that I can attribute to memory corruption.

Scott

flag, which calls SDL_AddEvent(). SDL_AddEvent adds MY pointer
to the event queue. ( All of this code is in events/SDL_events.c. )

No it doesn’t. Read it again.

m.On Mon, Nov 06, 2000 at 01:46:46PM -0800, Scott A. Herod wrote:


Programmer “Ha ha.” “Ha ha.” "What are you laughing at?"
Loki Software "Just the horror of being alive."
http://lokigames.com/~briareos/ - Tony Millionaire

Michael Vance wrote:

flag, which calls SDL_AddEvent(). SDL_AddEvent adds MY pointer
to the event queue. ( All of this code is in events/SDL_events.c. )

No it doesn’t. Read it again.

m.

You are correct, it makes a new pointer to my data.

< line 305 of SDL_events.c >

	if ( action == SDL_ADDEVENT ) {
                    for ( i=0; i<numevents; ++i ) {
                            used += SDL_AddEvent(&events[i]);
                    }
            } 

which calls into …

<line 248 of the same file.>
SDL_EventQ.event[SDL_EventQ.tail] = *event;

But, is the actual data copied? The key question is, Can I safely
free the structure in the following:

SDL_Event* e = (SDL_Event*) malloc( sizeof (SDL_Event) );
< fill in e >
SDL_PushEvent( e );
free( e );> On Mon, Nov 06, 2000 at 01:46:46PM -0800, Scott A. Herod wrote:

  SDL_EventQ.event[SDL_EventQ.tail] = *event; 

But, is the actual data copied? The key question is, Can I safely

Yes. Member-by-member structure copy.

free the structure in the following:

Yes, assuming you created it off the heap (which there is usually no
reason to do, I can’t remember why you said you were).

m.On Mon, Nov 06, 2000 at 03:13:21PM -0800, Scott A. Herod wrote:


Programmer “Ha ha.” “Ha ha.” "What are you laughing at?"
Loki Software "Just the horror of being alive."
http://lokigames.com/~briareos/ - Tony Millionaire