Unix Technical Forum

Re: Can we simplify win32 threading code

This is a discussion on Re: Can we simplify win32 threading code within the pgsql Hackers forums, part of the PostgreSQL category; --> > Currently PG win32 port mainly does the following to simulate signals: > > (*) the process who kill ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008, 05:04 AM
Magnus Hagander
 
Posts: n/a
Default Re: Can we simplify win32 threading code

> Currently PG win32 port mainly does the following to simulate signals:
>
> (*) the process who kill the signal:
> - put the signal in a named pipe, then it is done;
>
> (*) the process who should receive the signal:
> - a non-stop thread "pg_signal_thread" will read the signal
> from the pipe, and start another thread
> "pg_signal_dispatch_thread", which puts the signal in a local
> memory variable "pg_signal_queue" and
> SetEvent(local_memory_event_variable);
> - the main thread of this process could be awakened by the
> event from waiting status(like semop()) or
> CHECK_FOR_INTERRUPTS() actively;
>
>
> Could we simplify this process like this:
>
> (*) the process who kill the signal:
> - put the signal in a *shared memory variable
> pg_signal_queue* and
> SetEvent(*shared_memory_event_variable*), then it is done;
>
> (*) the process who should receive the signal:
> - the main thread of this process could be awakened by the
> event from waiting status(like semop()) or
> CHECK_FOR_INTERRUPTS() actively; -- there is no other threads
> of this process;
>
> Any show-stop reasons of not doing this?


Yeah, that should work. With one shared memory segment and one event for
each process, of course. The event can be the same one as is used now,
only it has to be named so it can be accessed externally.

It would do away with the thread, certainly. But it's not quite as
simple as you outline above - you'll need to replace the critical
section locking (easy, lightweight) with a mutex or something like that
(more complex, more heavy weight). But probably named pipes is more
heavy, yes.

You'll also need some way of delivering the feedback, I think - kill(0)
is supposed to tell you if there is a live process in th eother end, so
you can't just throw the signal out and hope for the best.

I think the named pipe parts of things is a leftover from back when we
were using APCs to interrupt the main thread - which required a separate
thread. But since we can't do that, this sounds like a reasonable
simplification.

//Magnus

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 05:04 AM
Andrew Dunstan
 
Posts: n/a
Default Re: Can we simplify win32 threading code



Magnus Hagander wrote:

>>(*) the process who kill the signal:
>> - put the signal in a *shared memory variable
>>pg_signal_queue* and
>>SetEvent(*shared_memory_event_variable*), then it is done;
>>
>>(*) the process who should receive the signal:
>> - the main thread of this process could be awakened by the
>>event from waiting status(like semop()) or
>>CHECK_FOR_INTERRUPTS() actively; -- there is no other threads
>>of this process;
>>
>>Any show-stop reasons of not doing this?
>>
>>

>
>Yeah, that should work. With one shared memory segment and one event for
>each process, of course. The event can be the same one as is used now,
>only it has to be named so it can be accessed externally.
>
>
>
>



I assume that this will not break the use of pg_ctl to deliver
pseudo-signals. That would be a show-stopper.

cheers

andrew




---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-11-2008, 05:05 AM
Qingqing Zhou
 
Posts: n/a
Default Re: Can we simplify win32 threading code


""Magnus Hagander"" <mha@sollentuna.net> writes
>
> Yeah, that should work. With one shared memory segment and one event for
> each process, of course. The event can be the same one as is used now,
> only it has to be named so it can be accessed externally.
>


Yes, the shared memory segment size could be controlled by MaxBackends.

> It would do away with the thread, certainly. But it's not quite as
> simple as you outline above - you'll need to replace the critical
> section locking (easy, lightweight) with a mutex or something like that
> (more complex, more heavy weight). But probably named pipes is more
> heavy, yes.
>


Yes, use mutex.

> You'll also need some way of delivering the feedback, I think - kill(0)
> is supposed to tell you if there is a live process in th eother end, so
> you can't just throw the signal out and hope for the best.
>


To simulate kill(0) we can test the process handle, just like we handle
waitpid().


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-11-2008, 05:09 AM
Qingqing Zhou
 
Posts: n/a
Default Re: Can we simplify win32 threading code

I have simplified the code according to the discussion. Now there is no pipe
or signaling threads, process access shared memory directly to pass signals.
Seems everything works fine except pg_ctl. I now have two choices to fix it:

(1) Record Shared memory name (it is already there) and the offset of
signaling shared memory in postmaster.pid; So the pg_ctl program can access
the shared memory (since it has write down the signal number there) and
SetEvent target process;

(2) Postmaster will startup a thread monitoring messages, pg_ctl simulate
"kill" by sending postmaster a message <target_pid, signum>, then postmaster
will forward this "signum" to "target_pid";

What do you think?

Regards,
Qingqing


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:37 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com