POSIX Threads

Someone knows how it to implement suspend()/resume() (Win32-like)
functionality on posix threads?
just I want to port my program to linux/solaris/win32, but solaris and
win32 native threads implementation have suspend()/resume and posix -
doesn’t.

Could anyone help me?

Someone knows how it to implement suspend()/resume() (Win32-like)
functionality on posix threads?
just I want to port my program to linux/solaris/win32, but solaris and
win32 native threads implementation have suspend()/resume and posix -
doesn’t.

Could anyone help me?

Nope, it’s a limitation of POSIX threads, as the suspend call may interrupt
the thread at a critical moment, possibly creating deadlock. The general
way of getting around this is having your thread periodically check a
"should I suspend" variable and handshaking with the thread that wants to
suspend it.

[Disclaimer: I’m not a POSIX thread guru, so look it up some more. :)]

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Sam Lantinga wrote:

Someone knows how it to implement suspend()/resume() (Win32-like)
functionality on posix threads?
just I want to port my program to linux/solaris/win32, but solaris and
win32 native threads implementation have suspend()/resume and posix -
doesn’t.

Could anyone help me?

Nope, it’s a limitation of POSIX threads, as the suspend call may interrupt
the thread at a critical moment, possibly creating deadlock.
Hmmm… Which sort of deadlock? because of unreleased mutex? But I always
can resume() thread after suspension… so thread can release mutex and
prevent any deadlocks…

The general
way of getting around this is having your thread periodically check a
"should I suspend" variable and handshaking with the thread that wants to
suspend it.
It’s not always possible, if I want to suspend() while thread performs
system call (blocking read() for example)

[Disclaimer: I’m not a POSIX thread guru, so look it up some more. :)]

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

I not belive that there is no way to implement suspend()\resume(). :frowning:

Jessica Reznor wrote:

Sam Lantinga wrote:

Someone knows how it to implement suspend()/resume() (Win32-like)
functionality on posix threads?
just I want to port my program to linux/solaris/win32, but solaris and
win32 native threads implementation have suspend()/resume and posix -
doesn’t.

Could anyone help me?

Nope, it’s a limitation of POSIX threads, as the suspend call may interrupt
the thread at a critical moment, possibly creating deadlock.
Hmmm… Which sort of deadlock? because of unreleased mutex? But I always
can resume() thread after suspension… so thread can release mutex and
prevent any deadlocks…

No… say one thread has a mutex, then another thread pauses it, and needs
access to something the other thread had locked… then one thread is locked,
and the other thread is suspended and can’t unlock the mutex.

The general
way of getting around this is having your thread periodically check a
"should I suspend" variable and handshaking with the thread that wants to
suspend it.
It’s not always possible, if I want to suspend() while thread performs
system call (blocking read() for example)

If your threads need to be suspended in the middle of a read, I think you’ve got
your program flow all wrong… trust me, you can do anything you need to, you
just have to do it the right way. ~,^

[Disclaimer: I’m not a POSIX thread guru, so look it up some more. :)]

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

I not belive that there is no way to implement suspend()\resume(). :frowning:

Of there is. But not the way you want to. That’s one of the reasons UNIX
doesn’t lock up very often, because it has been designed to avoid flaws like
that. Stability is more important than "an easy way to get something done."
I really don’t see a reason why you’d need to stop another thread except to stop
its access to certain data or from doing certain activities, which can be easily
enough handled by mutex and locking.

Sean Etc.

In article <3938D513.6A0397AD at grex.cyberspace.org>,
Jessica Reznor writes:

Someone knows how it to implement suspend()/resume() (Win32-like)
functionality on posix threads?
just I want to port my program to linux/solaris/win32, but solaris and
win32 native threads implementation have suspend()/resume and posix -
doesn’t.

Could anyone help me?

I know it is possible to emulate those functions on POSIX threads, using some
condition variables and some signals (USR1 and USR2). I even have working
code to do this in the ‘Programming with POSIX Threads’ book that is on my
desk. :wink:

Suspending/resuming threads asynchronously is generally a bad idea, but there
are sometimes some valid uses for it (for instance SimCity 3000 uses those
two extensively ! My current code just does pthread_kill()'s with SIGSTOP
and SIGCONT so fari. Hard to tell if it works as intended).

IMHO we should consider adding those functions to SDL. Mostly because pretty
much all threading libraries out there support it (except POSIX, but this
can be emulated), and some programs might need it…–
Stephane Peter
Programmer
Loki Entertainment Software

“Microsoft has done to computers what McDonald’s has done to gastronomy”

Stephane Peter wrote:

Someone knows how it to implement suspend()/resume() (Win32-like)
functionality on posix threads?
just I want to port my program to linux/solaris/win32, but solaris and
win32 native threads implementation have suspend()/resume and posix -
doesn’t.

Suspending/resuming threads asynchronously is generally a bad idea,
but there are sometimes some valid uses for it (for instance SimCity
3000 uses those two extensively ! My current code just does
pthread_kill()'s with SIGSTOP and SIGCONT so fari. Hard to tell if
it works as intended).

I was about to suggest using these two signals, as threads on Linux are
(almost) processes and should respond favorably to these. I wouldn’t bet
much on this working on other platforms with different thread
implementations, like Solaris, the GNU Pth library or FreeBSD.–
Pierre Phaneuf
Systems Exorcist