100% Quality Private Proxies » TOP Anonymous + Buy Proxy Cheap Price!100% Quality Private Proxies » TOP Anonymous + Buy Proxy Cheap Price!100% Quality Private Proxies » TOP Anonymous + Buy Proxy Cheap Price!100% Quality Private Proxies » TOP Anonymous + Buy Proxy Cheap Price!
    0
  •   was successfully added to your cart.
  • Buy Proxies
  • Features
  • Info
  • Contacts
  • Blog
  • Account

For The Same Price! 2x MORE PROXIES $750 Private Proxies 5,000 2,500 Private Proxies 50 100 250 500 1,000 100 200 500 1,000 2,000 Private Proxies Private Proxies Private Proxies Private Proxies $30 $50 $100 $180 $340 BUY! BUY! BUY! BUY! BUY! BUY!

I needed to get some thread help on home windows with quite simple headers for a library that I am engaged on however it needed to work on each Home windows and Linux. Since C11 threads usually are not broadly supported, this was an important alternative to be taught extra in regards to the Home windows API and POSIX threads. I made a decision to put up this right here as a result of I am not very skilled with threads and mutexes from each Home windows and POSIX and I might prefer it to be reviewed. Some issues are omitted as a result of they’re a part of the aforementioned library.

flags.h

/**
 * cmc_flags
 *
 * Defines frequent error codes utilized by the whole library.
 */
static struct
{
    int OK;        // No errors
    int THREAD;    // Generic error relating to threads
    int MUTEX;     // Generic error relating to mutexes
} cmc_flags = { 0, /* Omitted */ 8, 9 };

mutex.h

/**
 * A quite simple, header-only and minimalistic cross-platform mutex
 *
 * Varieties
 *  - cmc_mutex
 *
 * Capabilities
 *  - cmc_mtx_init
 *  - cmc_mtx_destroy
 *  - cmc_mtx_lock
 *  - cmc_mtx_unlock
 *  - cmc_mtx_trylock
 */

#embrace <stdbool.h>

#embrace "flags.h"

#if outlined(_WIN32)
#outline CMC_MUTEX_WINDOWS
#elif outlined(__unix__)
#outline CMC_MUTEX_UNIX
#else
#error "Unknown platform for CMC Mutex"
#endif

/* Platform particular contains */
#if outlined(CMC_MUTEX_WINDOWS)
#embrace <home windows.h>
#elif outlined(CMC_MUTEX_UNIX)
#embrace <errno.h>
#embrace <pthread.h>
#endif

/**
 * struct cmc_mutex
 *
 * A mutex wrapper.
 */
struct cmc_mutex
{
#if outlined(CMC_MUTEX_WINDOWS)
    HANDLE mutex;
#elif outlined(CMC_MUTEX_UNIX)
    pthread_mutex_t mutex;
#endif
    int flag;
};

/**
 * Purchase sources for a mutex.
 *
 * param mtx An uninitialized mutex wrapper.
 * return True or false if the mutex was efficiently initialized.
 */
static inline bool cmc_mtx_init(struct cmc_mutex *mtx)
{
#if outlined(CMC_MUTEX_WINDOWS)
    mtx->mutex = CreateMutex(NULL, FALSE, NULL);

    if (mtx->mutex == NULL)
        mtx->flag = cmc_flags.MUTEX;
    else
        mtx->flag = cmc_flags.OK;

    return mtx->mutex != NULL;

#elif outlined(CMC_MUTEX_UNIX)
    int err = pthread_mutex_init(&(mtx->mutex), NULL);

    if (err != 0)
        mtx->flag = cmc_flags.MUTEX;
    else
        mtx->flag = cmc_flags.OK;

    return err == 0;
#endif
}

/**
 * Launch all sources from a mutex. Calling this operate on a locked mutex
 * causes undefined habits.
 *
 * param mtx A mutex to be destroyed.
 * return True or false if the mutex was efficiently destroyed.
 */
static inline bool cmc_mtx_destroy(struct cmc_mutex *mtx)
{
#if outlined(CMC_MUTEX_WINDOWS)
    if (!CloseHandle(mtx->mutex))
    {
        mtx->flag = cmc_flags.MUTEX;
        return false;
    }

    mtx->flag = cmc_flags.OK;
    return true;

#elif outlined(CMC_MUTEX_UNIX)
    if (pthread_mutex_destroy(&(mtx->mutex)) != 0)
    {
        mtx->flag = cmc_flags.MUTEX;
        return false;
    }

    mtx->flag = cmc_flags.OK;
    return true;
#endif
}

/**
 * Locks a mutex. If the mutex is already locked, the thread is blocked till
 * the mutex could be acquired.
 *
 * param mtx A mutex to be locked.
 * return True or false if the lock on the mutex was efficiently acquired.
 */
static inline bool cmc_mtx_lock(struct cmc_mutex *mtx)
{
#if outlined(CMC_MUTEX_WINDOWS)
    DWORD consequence = WaitForSingleObject(mtx->mutex, INFINITE);

    if (consequence == WAIT_FAILED || consequence == WAIT_ABANDONED)
    {
        mtx->flag = cmc_flags.MUTEX;
        return false;
    }

    mtx->flag = cmc_flags.OK;
    return true;

#elif outlined(CMC_MUTEX_UNIX)
    if (pthread_mutex_lock(&mtx->mutex) != 0)
    {
        mtx->flag = cmc_flags.MUTEX;
        return false;
    }

    mtx->flag = cmc_flags.OK;
    return true;
#endif
}

/**
 * Unlocks a mutex. If the mutex is already locked, the thread is blocked till
 * the mutex could be acquired.
 *
 * param mtx A mutex to be unlocked.
 * return True or false if the mutex was efficiently unlocked.
 */
static inline bool cmc_mtx_unlock(struct cmc_mutex *mtx)
{
#if outlined(CMC_MUTEX_WINDOWS)
    if (!ReleaseMutex(mtx->mutex))
        mtx->flag = cmc_flags.MUTEX;
    else
        mtx->flag = cmc_flags.OK;

    return mtx->flag == cmc_flags.OK;

#elif outlined(CMC_MUTEX_UNIX)
    if (pthread_mutex_unlock(&mtx->mutex) != 0)
        mtx->flag = cmc_flags.MUTEX;
    else
        mtx->flag = cmc_flags.OK;

    return mtx->flag == cmc_flags.OK;
#endif
}

/**
 * Tries to lock a mutex. If the mutex is already locked, the thread will not be
 * blocked and the operate returns false.
 *
 * param mtx A mutex to attempt to lock.
 * return True or false if the lock on the mutex was efficiently acquired.
 */
static inline bool cmc_mtx_trylock(struct cmc_mutex *mtx)
{
#if outlined(CMC_MUTEX_WINDOWS)
    DWORD consequence = WaitForSingleObject(mtx->mutex, 0);

    if (consequence == WAIT_FAILED || consequence == WAIT_ABANDONED)
    {
        mtx->flag = cmc_flags.MUTEX;
        return false;
    }

    mtx->flag = cmc_flags.OK;
    return consequence != WAIT_TIMEOUT;

#elif outlined(CMC_MUTEX_UNIX)
    int err = pthread_mutex_trylock(&mtx->mutex);

    if (err == EINVAL || err == EFAULT)
        mtx->flag = cmc_flags.MUTEX;
    else
        mtx->flag = cmc_flags.OK;

    return err == 0;
#endif
}

thread.h

/**
 * A quite simple, header-only utility for spawning and becoming a member of threads
 *
 * Varieties
 *  - cmc_thread
 *  - cmc_thread_proc
 *
 * Capabilities
 *  - cmc_thrd_create
 *  - cmc_thrd_join
 */

#embrace <inttypes.h>
#embrace <stdbool.h>

#embrace "flags.h"

#if outlined(_WIN32)
#outline CMC_THREAD_WINDOWS
#elif outlined(__unix__)
#outline CMC_THREAD_UNIX
#else
#error "Unknown platform for CMC Threads"
#endif

#if outlined(CMC_THREAD_WINDOWS)
#embrace <home windows.h>
#elif outlined(CMC_THREAD_UNIX)
#embrace <pthread.h>
#endif

/* The kind of a course of run by a thread */
typedef int (*cmc_thread_proc)(void *);

/**
 * struct cmc_thread
 *
 * A thread wrapper.
 */
struct cmc_thread
{
#if outlined(CMC_THREAD_WINDOWS)
    HANDLE thread;
#elif outlined(CMC_THREAD_UNIX)
    pthread_t thread;
#endif
    int flag;
    void *args;
    cmc_thread_proc course of;
};

/* A thread wrapper */
#if outlined(CMC_THREAD_WINDOWS)
static DWORD cmc_thread_wrapper(void *arg)
#elif outlined(CMC_THREAD_UNIX)
static void *cmc_thread_wrapper(void *arg)
#endif
{
    struct cmc_thread *thr = (struct cmc_thread *)arg;

    int consequence = thr->course of(thr->args);

#if outlined(CMC_THREAD_WINDOWS)
    return consequence;
#elif outlined(CMC_THREAD_UNIX)
    return (void *)(intptr_t)consequence;
#endif
}

/**
 * Creates and spawns a brand new thread.
 *
 * param thr  An uninitialized thread wrapper.
 * param proc Pointer to a operate that can run in a brand new thread.
 * param args The arguments handed to the proc operate.
 * return True or false if the thread creation was successfull.
 */
static inline bool cmc_thrd_create(struct cmc_thread *thr, cmc_thread_proc proc,
                                   void *args)
{
#if outlined(CMC_THREAD_WINDOWS)
    thr->args = args;
    thr->course of = proc;
    thr->thread = CreateThread(NULL, 0, cmc_thread_wrapper, thr, 0, NULL);

    if (!thr->thread)
        thr->flag = cmc_flags.THREAD;
    else
        thr->flag = cmc_flags.OK;

    return thr->flag == cmc_flags.OK;

#elif outlined(CMC_THREAD_UNIX)
    thr->args = args;
    thr->course of = proc;
    if (pthread_create(&(thr->thread), NULL, cmc_thread_wrapper, thr) != 0)
        thr->flag = cmc_flags.THREAD;
    else
        thr->flag = cmc_flags.OK;

    return thr->flag == cmc_flags.OK;
#endif
}

/**
 * Blocks the present thread till the goal thread terminates.
 *
 * param thr    The goal thread to attend on.
 * param consequence The worth returned by the goal thread. Optionally available.
 * return True or false if the be part of was successfull.
 */
static inline bool cmc_thrd_join(struct cmc_thread *thr, int *consequence)
{
#if outlined(CMC_THREAD_WINDOWS)
    if (WaitForSingleObject(thr->thread, INFINITE) == WAIT_FAILED)
    {
        thr->flag = cmc_flags.THREAD;
        return false;
    }

    DWORD exit_code;

    if (consequence)
    {
        if (GetExitCodeThread(thr->thread, &exit_code) == 0)
        {
            thr->flag = cmc_flags.THREAD;
            return false;
        }
        else
            *consequence = (int)exit_code;
    }

    thr->flag = cmc_flags.OK;

    if (CloseHandle(thr->thread) == 0)
    {
        thr->flag = cmc_flags.THREAD;
        return false;
    }

    thr->flag = cmc_flags.OK;
    return true;

#elif outlined(CMC_THREAD_UNIX)
    void *exit_value;

    if (pthread_join(thr->thread, &exit_value) != 0)
    {
        thr->flag = cmc_flags.THREAD;
        return false;
    }

    if (consequence)
    {
        *consequence = (int)(intptr_t)exit_value;
    }

    thr->flag = cmc_flags.OK;
    return true;

#endif
}

instance.c

#embrace <stdio.h>
#embrace <stdlib.h>
#embrace "mutex.h"
#embrace "thread.h"

#outline NTHREADS 1000

struct cmc_mutex lck;

/* What number of trylock failed */
struct cmc_mutex flck;
int trylock_fails = 0;

int thread_process(void *arg)
{
    int *sum = (int *)arg;

    if (rand() % 2 == 0)
    {
        cmc_mtx_lock(&lck);
        for (int i = 0; i < 1000; i++)
            *sum += 1;
        cmc_mtx_unlock(&lck);
    }
    else
    {
        if (!cmc_mtx_trylock(&lck))
        {
            cmc_mtx_lock(&flck);
            trylock_fails += 1;
            cmc_mtx_unlock(&flck);

            return 0;
        }

        for (int i = 0; i < 1000; i++)
            *sum += 1;

        cmc_mtx_unlock(&lck);
    }

    return 0;
}

int essential(void)
{
    cmc_mtx_init(&lck);
    cmc_mtx_init(&flck);

    struct cmc_thread threads[NTHREADS];

    int sum = 0;

    for (int i = 0; i < NTHREADS; i++)
        cmc_thrd_create(&threads[i], thread_process, &sum);

    for (int i = 0; i < NTHREADS; i++)
        cmc_thrd_join(&threads[i], NULL);

    printf("Whole sum       : %dn", sum);
    printf("Failed trylocks : %dn", trylock_fails);
}
```

Best Quality Private Proxies by Proxyti:

fully anonymous

100% anonymous and safe reliable private proxies

1,000 mb/s speed

Blazing fast proxy servers with up to 1,000 mb/s speed

Elite quality

Best quality proxies from world and USA locations

Unlimited bandwidth

No limits of using your proxies - truly unlimited bandwidth

Buy Now - Get 2X More Proxies:

100 Private Proxies

$30/month

$0.3 Per Proxy
Private and Anonymous
Ultra Fast Speed
Unlimited Bandwidth
USA or Worldwide
2X More Proxies!
Buy now!

200 Private Proxies

$50/month

$0.25 Per Proxy
Private and Anonymous
Ultra Fast Speed
Unlimited Bandwidth
USA or Worldwide
2X More Proxies!
Buy now!

500 Private Proxies

$100/month

$0.2 Per Proxy
Private and Anonymous
Ultra Fast Speed
Unlimited Bandwidth
USA or Worldwide
2X More Proxies!
Buy now!

1,000 Private Proxies

$180/month

$0.18 Per Proxy
Private and Anonymous
Ultra Fast Speed
Unlimited Bandwidth
USA or Worldwide
2X More Proxies!
Buy now!

2,000 Private Proxies

$340/month

$0.17 Per Proxy
Private and Anonymous
Ultra Fast Speed
Unlimited Bandwidth
USA or Worldwide
2X More Proxies!
Buy now!

5,000 Private Proxies

$750/month

$0.15 Per Proxy
Private and Anonymous
Ultra Fast Speed
Unlimited Bandwidth
USA or Worldwide
2X More Proxies!
Buy now!

Our Unbeatable Proxy Features:

Anonymous Proxies

100% security with our proxies – anonymous and secure proxy experience

Ultra Fast Speed

Proxyti offers up to 1,000 mb/s ultra fast proxy speed – feel the real power!

Unlimited Bandwidth

No data limits for your proxies – truly unlimited proxy bandwidth for you!

Proxy Authentication

We secure proxies with IP authentication – use your proxies with your own IP

Elite Quality

Highest proxy quality guarantee with supported HTTP/HTTPS and SOCKS connections

Great Prices

Proxyti offers great proxies for great prices – this is what we call new proxy era!

USA Locations

You can choose USA or random proxies locations when ordering for free

No Limitations

We don’t have any limits – you can use your proxies with every software or program!

Lots Of Subnets

The more proxies you buy, the more subnets you get – it is worth ordering more!

Semi Dedicated

Our proxies are shared with maximum of 5 users at a time, but they are still anonymous

Fast Delivery

We deliver your ordered proxies in your email in .txt file – this is simple as that

Awesome Support

Have any questions or want more information – please contact us anytime!


About Proxyti

We deliver quality private proxy solutions for everyone – fast, anonymous, secure and unlimited proxies by Proxyti.
 

Secure Payments

All payments are made via Paypal – safe and secure payment system administrator

Top rated products

  • 200 Private Proxies
    Rated 4.83 out of 5
    $50.00 / month
  • 1000 Private Proxies
    Rated 4.82 out of 5
    $180.00 / month

Connect with us

Copyright Proxyti.com | All Rights Reserved
  • Buy Proxies
  • Features
  • Info
  • Contacts
  • Blog
  • Account
100% Quality Private Proxies » TOP Anonymous + Buy Proxy Cheap Price!
    0 items