Hello everyone))

Guys please tell me - is there any way to create thread in lunux , which will not executed itself (at all) - until will get SIGCONT signal?

I can't thread self stopping after creation , because in this case - we cann't be sure that the thread will be stopped exactly before (not after) parent process will send SIGCONT to it - that's possible that the thread will be find in not active state after getting SIGCONT from another one (because of multithreading)

So I need to be sure that the thread has been stoped by the moment the other thread send the SIGCONT to the first one.

If someone know - how to do this - please help.

big thanks in advance))

I don't think it is possible. What exactly are you trying to achieve? I mean, is using signals a requirement?

commented: +++++++++++ +3

your intuition is good)
I would like to use signals .
Yes - to be concrete - for example - i have 3 threads (list) =
1) the first one reads first txt file into memory
2) the second reads second txt file into memory
3) and the third thread compare each other arrays , which had been made by the previous two threads

I need perform all operations in such order as in list , because all of them(threads)))) use console to show some notifications about own work.

In the general case this situation needs that at least the third thread will be stoped just after creation.

I need perform all operations in such order as in list

This sort of defeats the purpose of multithreading...

this situation needs that at least the third thread will be stoped just after creation

A semaphore or a conditional variable would do it much better.

This sort of defeats the purpose of multithreading...

yes - you're right - but what about this -

this situation needs that at least the third thread will be stoped just after creation

you said =

A semaphore or a conditional variable would do it much better.

so - there's no way to stop comparision thread safety using signals ?

in windows there's WaitForMultipleObjects () function - it can solve this problem, but in linux....can't))

so - there's no way to stop comparison thread safely using signals ?

No. The pthread_create man page explicitly says that
The set of pending signals for the new thread is empty

thank you robea but my problem is related to Linux)

You can do this directly with a mutex. It is not a signal, but is more suited to synchronizing threads. Example:

pthread_mutex_t the_lock = PTHREAD_MUTEX_INITIALIZER;

void * thread_fun(void * ignore) {
    struct timeval tv;
    pthread_mutex_lock (&the_lock);
    gettimeofday (&tv, NULL);
    fprintf(stderr, "thread: %d.%06d\n", tv.tv_sec, tv.tv_usec);
    return NULL;
}

int main () {

    pthread_t thr;
    struct timeval tv;

    /* lock the mutex *before* creating the thread */
    pthread_mutex_lock (&the_lock);
    pthread_create (&thr, NULL, thread_fun, NULL);
    fprintf (stderr, "main snoozing for a bit...\n");
    sleep (2);
    gettimeofday (&tv, NULL);
    fprintf(stderr, "main: %d.%06d\n", tv.tv_sec, tv.tv_usec);

    /* Unlock and wait for thread */
    pthread_mutex_unlock (&the_lock);
    pthread_join (thr, NULL);
    return 0;
}

In that example, the thread will not execute beyond the lock request until the calling thread releases the lock on the mutex.

commented: ++++++++++++ +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.