Create workflows?

Is there any way to do "workflows". Basically, I tried to create threads every time I needed it, and this led to a slowdown than using a single thread, because creating a new thread is always expensive. Will there be a way to create workflows when I first launch the application and then give them work when necessary?

thank

+3
source share
3 answers

Yes, you can create streams in front and make them wait for signals to appear and start their work.

These signals can be message queues or semaphores or any other way of exchanging between threads.

- UNIX, , . ( , ) .

, , slave- .

, ( pthreads). , , .

, "" , , ( ).

, " " - , .

, , , . , , , .


, . , , , ( ).

- :

master:
    minslaves = 7
    maxslaves = 20
    maxtime = 600
    numslaves = 0
    freeslaves = 0

    while running:
        while numslaves < minslaves:
            increment numslaves and freeslaves
            start a slave
        endwhile
        wait for work
        if freeslaves = 0 and numslaves < maxslaves:
            start a slave
        endif
        queue work to slavequeue
    endwhile
    while numslaves > 0:
        wait
    endwhile
    exit

slave:
    while running:
        get work from slavequeue with timeout
        if timed out:
            if time since last work > maxtime and numslaves > minslaves:
                break out of while loop
            endif
            restart while loop
        endif
        decrement freeslaves
        do the work
        increment freeslaves
    endwhile
    decrement numslaves and freeslaves
    exit

( , , numslaves, freeslaves, slavequeue , ).

, , - . - : -)

+7

. - , , .

0

win32 - esp vista windows 7 . , , .

, (ConcRT, , ), Visual ++ 2010, ( ). . MSDN - http://msdn.microsoft.com/en-us/library/dd492418.aspx

0

Source: https://habr.com/ru/post/1753462/


All Articles