Exemple #1
0
int main(int argc, char** argv) {

    aInit(&argc, &argv);
    
    int sizeIn1, sizeIn2, sizeOut, iterators;

    scanf("%d %d %d %d", &sizeIn1, &sizeIn2, &sizeOut, &iterators);
    
    thr_param_t param[iterators];
    athread_t thr[iterators];
    
    int i;

    for(i=0; i < iterators; i++) {

        char *a = malloc(sizeIn1*sizeof(char));
        char *b = malloc(sizeIn2*sizeof(char));;
        char *out = malloc(sizeOut*sizeof(char));

        scanf("%s",a);
        scanf("%s",b);
    
        param[i]._a = a;
        param[i]._b = b;
        param[i]._out = out;

        athread_create(&thr[i], NULL,(void*)& lcs, (void*) param); 

        athread_join(thr[i], NULL);

        free(a);
        free(b);
        free(out);
    }

    aTerminate();
    return 0;
}
Exemple #2
0
AValue AThreadCreate(AThread *t, AValue *frame)
{
    AThread *newThread;
    athread_t threadId;
    ABool isWaiting;
    AValue *threadData;

    /* Call the thread function always with no arguments. */
    frame[2] = AMakeArray(t, 0);

    threadData = AAllocUnmovable(sizeof(AValue) + THREAD_DATA_SIZE);
    if (threadData == NULL)
        return ARaiseMemoryErrorND(t);

    AInitNonPointerBlockOld(threadData, THREAD_DATA_SIZE);

    *t->tempStack = ANonPointerBlockToValue(threadData);
    ASetMemberDirect(t, frame[0], A_THREAD_DATA, *t->tempStack);
    threadData = AValueToPtr(*t->tempStack);

    if (athread_mutex_init(GetThreadMutex(threadData), NULL)
        || athread_cond_init(GetThreadCond(threadData), NULL))
        return ARaiseMemoryErrorND(t);

    athread_mutex_lock(&AThreadMutex);

    if (NumWaitingThreads > 0) {
        NumWaitingThreads--;
        isWaiting = TRUE;
        AAvoidWarning_M(newThread = NULL);
    } else {
        athread_mutex_unlock(&AThreadMutex);

        newThread = ACreateThread(frame + 3);
        if (newThread == NULL)
            return ARaiseMemoryErrorND(t);

        isWaiting = FALSE;

        athread_mutex_lock(&AThreadMutex);
    }

    /* Wait until the argument buffer is not full. */
    while (ArgBufFirst == NextInd(ArgBufLast)) {
        AllowFreezeNoLock();
        athread_cond_wait(&ArgBufRemoveCond, &AThreadMutex);
        DisallowFreezeNoLock();
    }

    /* Store thread object, function to be executed and arguments. */
    AThreadArgBuffer[3 * ArgBufLast    ] = frame[0];
    AThreadArgBuffer[3 * ArgBufLast + 1] = frame[1];
    AThreadArgBuffer[3 * ArgBufLast + 2] = frame[2];

    ArgBufLast = NextInd(ArgBufLast);

    athread_mutex_unlock(&AThreadMutex);

    if (isWaiting)
        athread_cond_signal(&ArgBufInsertCond);
    else {
        int result = athread_create(&threadId, BeginNewThread, newThread);
        if (result)
            return ARaiseMemoryErrorND(t); /* FIX: bad */

        /* Perhaps store new thread id somewhere. */
    }

    return frame[0];
}