Skip to contentSkip to conversation

How to suspend a thread (without pthread)

DISCUSSION SVisor 2 participants 3 messages May 25, 2005

lore
Share & tools
lore

SVisor

author
#0 lore raw

As subject says,

I need to suspend threads (for locking purpose) but I do not want to use Posix threads library (pthread). Neither do I want to access __KERNEL__ protected parts of the kernel API.

There must be a user accesible API for this. The nearest Ive found is sched_yield( ), but it just moves a thread (process) to the end of run-queue.

// Jarmo

#1 lore raw

what do u mean by suspend?
sleep/block? if ur looking for a time-based threadsleep maybe u can make use(improvise) with the select() function.

for example:

void threadSleep( int sec )
{
struct timeval stTimeOut;
int nSel;

stTimeOut.tv_sec = sec; /* Set the number of seconds */
stTimeOut.tv_usec = 0; /* Set the number of micro seconds */

nSel = select( 0, NULL, NULL, NULL, &stTimeOut);
}

what's wrong with using the pthread library? (ex: pthread_mutex_lock, pthread_mutex_unlock) license issues? client-preference issues? library-comptability?

Quoted 14 lines · SVisor

As subject says,

I need to suspend threads (for locking purpose) but I do not want to use Posix threads library (pthread). Neither do I want to access __KERNEL__ protected parts of the kernel API.

There must be a user accesible API for this. The nearest Ive found is sched_yield( ), but it just moves a thread (process) to the end of run-queue.

// Jarmo

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#2 lore raw
Quoted 3 lines · Ron Michael Khu

what do u mean by suspend?
sleep/block? if ur looking for a time-based threadsleep maybe u can make use(improvise) with the select() function.

I mean sleep until awoken. Ive used a yielding spin lock this far. But there must be a better way. I cant use a timer (like select).

...

Quoted 2 lines

what's wrong with using the pthread library? (ex: pthread_mutex_lock, pthread_mutex_unlock) license issues? client-preference issues? library-comptability?

pthread doesnt play well with clone( ). LGPL (which is pthread:s licens) is not realy a problem (today). But the truth is that I try to avoid (L)GPL as much as possible. Especially when writing support code (like libraries) which future use is unknown.

// Jarmo

...

Quoted 3 lines
Quoted 3 lines

I need to suspend threads (for locking purpose) but I do not want to use Posix threads library (pthread). Neither do I want to access __KERNEL__ protected parts of the kernel API.

There must be a user accesible API for this. The nearest Ive found is sched_yield( ), but it just moves a thread (process) to the end of run-queue.

...