๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: rec.arts.sf.written
Article #652

Re: โ€œThe end of software secrecy is almost upon

#652
From: Chris M. Thomasson
Date: Mon, 26 Oct 2026 00:22
582 lines
10905 bytes
On 10/25/2026 1:56 PM, Michael S wrote:
> On Sun, 25 Oct 2026 08:41:48 -0000 (UTC)
> boltar@caprica.universe wrote:
> 
>> On Sun, 25 Oct 2026 00:28:19 -0000 (UTC)
>> cross@spitfire.i.gajendra.net (Dan Cross) gabbled:
>>> In article <20261025011151.000038ef@yahoo.com>,
>>>> Now, would it be the first thing I would want like addition to C++
>>>> standard library? No it would not be.
>>>> The first thing would be IPv4 communication, sockets, poll etc...
>>>
>>> POSIX has all of that.  POSIX also has a process model.  Why not
>>> just make POSIX a part of the language, then?  (Answer that and
>>> you may start to understand why this is harder than it looks
>>> for C++ [and C].)
>>
>> No, it isn't. How similar do you think the posix and windows threading
>> model/api are? Yet somehow C++ provides a common wrapper for both.
> 
> Actually, implementing C++11 (or C11) threads fully in user space on
> pre-Vista Win32 (i.e. before addition of support for conditional
> variables to OS API) would be quite challenging. I don't know if
> anybody bothered.
> I think that it is possible, but if you want it robust then it (cond.
> variables) will cost you significant overhead relatively to "native"
> synchronization primitives.
> 
>> There is no reason the same can't be done for processes and your
>> irrelevant waffle about past issues of threading on *nix don't change
>> that.
>>
> 
> Dick-measuring competitions are integral part of Usenet tradition.
> 
> 
> 
> 
> 
> 

I tried to do a little something, no atomics, but, since I am able to 
access comp.lang.c++ agai, lets see if I can find it:

https://groups.google.com/g/comp.lang.c/c/WPH7ed5uS4Y/m/ohiP-hUWkcAJ

Content:
___________________________________



________________________________________________________________
#if ! defined (CT_C11_THREADS_H_EMULATION_H)
# define CT_C11_THREADS_H_EMULATION_H 1
# if defined (__cplusplus)
extern "C"
{
# endif



#if defined (CT_C11_THREADS_H_PRINTF_LOG)
# include <stdio.h>
# define CT_C11_THREADS_H_PRINTF(mp_exp) printf mp_exp
#else
# define CT_C11_THREADS_H_PRINTF(mp_exp) ((void)(0))
#endif




#include <stdlib.h>
#include <pthread.h>
#include <assert.h>


typedef int (*ct_thrd_start_t) (void*);

struct ct_thrd_user
{
pthread_t ptid;
};


struct ct_thrd_sys
{
ct_thrd_start_t fp_user;
void* user_ctx;
int user_ret;
};


enum ct_thrd_sys_status
{
ct_thrd_success = 0,
ct_thrd_nomem = 1,
ct_thrd_timedout = 2,
ct_thrd_busy = 3,
ct_thrd_error = 4
};





/* low-level system threading API's
__________________________________________________________________*/
static struct ct_thrd_sys*
ct_thrd_sys_create(
ct_thrd_start_t fp_user,
void* user_ctx
);

static void
ct_thrd_sys_destroy(
struct ct_thrd_sys* const self
);

static void*
ct_thrd_sys_entry(
void* self_raw
);



struct ct_thrd_sys*
ct_thrd_sys_create(
ct_thrd_start_t fp_user,
void* user_ctx
){
struct ct_thrd_sys* const self = malloc(sizeof(*self));

if (self)
{
self->fp_user = fp_user;
self->user_ctx = user_ctx;
self->user_ret = 0;
}

CT_C11_THREADS_H_PRINTF(("ct_thrd_sys_create = %p\r\n", (void*)self));

return self;
}

void
ct_thrd_sys_destroy(
struct ct_thrd_sys* const self
){
free(self);

CT_C11_THREADS_H_PRINTF(
("ct_thrd_sys_destroy(self = %p)\r\n", (void*)self)
);
}


void*
ct_thrd_sys_entry(
void* self_raw
){
struct ct_thrd_sys* const self = self_raw;

CT_C11_THREADS_H_PRINTF(
("ct_thrd_sys_entry(self_raw = %p):Enter\r\n", self_raw)
);

self->user_ret = self->fp_user(self->user_ctx);

CT_C11_THREADS_H_PRINTF(
("ct_thrd_sys_entry(self_raw = %p):Exit = %p\r\n", self_raw,
(void*)self)
);

return self;
}






/* C11 emulation API layer
__________________________________________________________________*/


/* Threading API
______________________________________________________________*/
typedef struct ct_thrd_user ct_thrd_t;


static int
ct_thrd_create(
ct_thrd_t* uself,
ct_thrd_start_t fp_user,
void* user_ctx
);

static int
ct_thrd_join(
ct_thrd_t self,
int* user_retv
);


int
ct_thrd_create(
ct_thrd_t* uself,
ct_thrd_start_t fp_user,
void* user_ctx
){
struct ct_thrd_sys* const self =
ct_thrd_sys_create(fp_user, user_ctx);

if (self)
{
int status = pthread_create(&uself->ptid, NULL, ct_thrd_sys_entry,
self);

if (! status)
{
return ct_thrd_success;
}

ct_thrd_sys_destroy(self);
}

return ct_thrd_nomem;
}


int
ct_thrd_join(
ct_thrd_t self,
int* user_retv
){
void* ptjret = NULL;

pthread_join(self.ptid, &ptjret);

if (ptjret)
{
struct ct_thrd_sys* const self = ptjret;

if (user_retv)
{
*user_retv = self->user_ret;
}

ct_thrd_sys_destroy(self);

return ct_thrd_success;
}

return ct_thrd_error;
}




/* Thread Specific Storage API
______________________________________________________________*/
typedef pthread_key_t ct_tss_t;
typedef void(*ct_tss_dtor_t) (void*);

static int
ct_tss_create(
ct_tss_t* self,
ct_tss_dtor_t fp_user_dtor
);

static void
ct_tss_delete(
ct_tss_t self
);

static int
ct_tss_set(
ct_tss_t self,
void* user_ctx
);

#define ct_tss_get(mp_self) pthread_getspecific((mp_self))



int
ct_tss_create(
ct_tss_t* self,
ct_tss_dtor_t fp_user_dtor
){
int status = pthread_key_create(self, fp_user_dtor);

if (!status)
{
return ct_thrd_success;
}

return ct_thrd_error;
}


void
ct_tss_delete(
ct_tss_t self
){
int status = pthread_key_delete(self);

if (! status)
{
return;
}

assert(! status);
}


int
ct_tss_set(
ct_tss_t self,
void* user_ctx
){
int status = pthread_setspecific(self, user_ctx);

if (!status)
{
return ct_thrd_success;
}

return ct_thrd_error;
}




/* Mutex API
______________________________________________________________*/
typedef pthread_mutex_t ct_mtx_t;

enum {
ct_mtx_plain = 1,
ct_mtx_recursive = 2,
ct_mtx_timed = 4
};


int
ct_mtx_init(
ct_mtx_t* self,
int type
){
if (type == ct_mtx_plain)
{
int status = pthread_mutex_init(self, NULL);

if (! status)
{
return ct_thrd_success;
}
}

return ct_thrd_error;
}


void
ct_mtx_destroy(
ct_mtx_t* self
){
int status = pthread_mutex_destroy(self);

if (! status)
{
return;
}

assert(! status);
}


int
ct_mtx_lock(
ct_mtx_t* self
){
int status = pthread_mutex_lock(self);

if (! status)
{
return ct_thrd_success;
}

assert(! status);

return ct_thrd_error;
}


int
ct_mtx_unlock(
ct_mtx_t* self
){
int status = pthread_mutex_unlock(self);

if (!status)
{
return ct_thrd_success;
}

assert(! status);

return ct_thrd_error;
}




/* Mutex API
______________________________________________________________*/
typedef pthread_cond_t ct_cnd_t;

int
ct_cnd_init(
ct_cnd_t* self
){
int status = pthread_cond_init(self, NULL);

if (! status)
{
return ct_thrd_success;
}

return ct_thrd_error;
}


void
ct_cnd_destroy(
ct_cnd_t* self
){
int status = pthread_cond_destroy(self);

if (! status)
{
return;
}

assert(! status);
}


int
ct_cnd_signal(
ct_cnd_t* self
){
int status = pthread_cond_signal(self);

if (! status)
{
return ct_thrd_success;
}

assert(! status);

return ct_thrd_error;
}


int
ct_cnd_broadcast(
ct_cnd_t* self
){
int status = pthread_cond_broadcast(self);

if (! status)
{
return ct_thrd_success;
}

assert(! status);

return ct_thrd_error;
}


int
ct_cnd_wait(
ct_cnd_t* self,
ct_mtx_t* mtx
){
int status = pthread_cond_wait(self, mtx);

if (! status)
{
return ct_thrd_success;
}

assert(! status);

return ct_thrd_error;
}






/* Mock up the final C11 API with some macros... ;^o
______________________________________________________________*/



/* C11 threading API
_________________________________________________*/
#define thrd_success ct_thrd_success
#define thrd_nomem ct_thrd_nomem
#define thrd_timedout ct_thrd_timedout
#define thrd_busy ct_thrd_busy
#define thrd_error ct_thrd_error

#define thrd_t ct_thrd_t

#define thrd_create ct_thrd_create
#define thrd_join ct_thrd_join



/* C11 thread specific storage API
_________________________________________________*/
#define tss_t ct_tss_t

#define tss_create ct_tss_create
#define tss_delete ct_tss_delete
#define tss_set ct_tss_set
#define tss_get ct_tss_get



/* C11 mutex API
_________________________________________________*/
#define mtx_plain ct_mtx_plain
#define mtx_recursive ct_mtx_recursive
#define mtx_timed ct_mtx_timed

#define mtx_t ct_mtx_t

#define mtx_init ct_mtx_init
#define mtx_destroy ct_mtx_destroy
#define mtx_lock ct_mtx_lock
#define mtx_unlock ct_mtx_unlock



/* C11 condition variable API
_________________________________________________*/
#define cnd_t ct_cnd_t

#define cnd_init ct_cnd_init
#define cnd_destroy ct_cnd_destroy
#define cnd_signal ct_cnd_signal
#define cnd_broadcast ct_cnd_broadcast
#define cnd_wait ct_cnd_wait




# if defined (__cplusplus)
}
# endif
#endif
________________________________________________________________



This is in my personal coding style. I am sorry if it ends up pissing you
off!

;^o




Anyway, what do you think?

:^)
Technical Details
Message-ID: <11bm6g4$3hjr$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11amvre$15far$1@dont-email.me> <11bj08r$309uk$1@dont-email.me> <11bj7na$5bt$1@reader2.panix.com> <20261025011151.000038ef@yahoo.com> <11bjif3$7p0$1@reader2.panix.com> <11bkfcc$104cc$1@dont-email.me> <20261025225619.000074a5@yahoo.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Newsgroups: rec.arts.sf.written,comp.lang.fortran,comp.lang.c++,alt.comp.lang.rust,alt.folklore.computers
Subject: Re: โ€œThe end of software secrecy is almost upon
Date: Sun, 25 Oct 2026 17:22:28 -0700
Organization: A noiseless patient Spider
Lines: 582
Message-ID: <11bm6g4$3hjr$1@dont-email.me>
References: <11amvre$15far$1@dont-email.me> <11bj08r$309uk$1@dont-email.me>
 <11bj7na$5bt$1@reader2.panix.com> <20261025011151.000038ef@yahoo.com>
 <11bjif3$7p0$1@reader2.panix.com> <11bkfcc$104cc$1@dont-email.me>
 <20261025225619.000074a5@yahoo.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 26 Oct 2026 00:22:30 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="116347"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/Nc1nl8v1wuhOwxayMYp9Ol9ZSRFsmdXI="; posting-host="49da529de1e605d0c2cf1bd5b7b86f4a"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:OEnox+uBgYLDLqNpHQSaDJnX0CE= sha256:MAwN9hyfuh+dye7m3kUbwOxvZwmyhbt7OT3tFP95V3w=
	sha1:g8/DIZCya7QR46gKyzEi+uweptc= sha256:zbe+93Pdx5mMoXgl54Kpx4d0k8GfkdpU8BZD1WqN6SA=
In-Reply-To: <20261025225619.000074a5@yahoo.com>
Content-Language: en-US