mmap on MacOS

let’s see a snippet of code, Guess what happened on MacOS ?

 size_t pageSize = getpagesize();

  std::cout << " page size is " << pageSize << std::endl;

  int handle = shm_open("mempool_tag", O_CREAT | O_RDWR , 0777 );

  if (handle) {
     std::cout << std::setw(20) << "shm_open yield with  " << handle << std::endl;
  }
  else {
     ftruncate(handle, GetPoolSize());  
  }
  
  ftruncate(handle, GetPoolSize());  

  char* region = (char*) mmap( NULL, 
                               GetPoolSize(),
                               PROT_READ | PROT_WRITE | PROT_EXEC,
                               MAP_ANONYMOUS,
                               handle,
                               GetPoolSize()*20);
  if (region == MAP_FAILED) {
     return -1; 
  }

  return 0;

NerdTree hacks

I came with the problem when exit from the vim with “:q” command.

NERDTree still display after :q command

and this seems the buffer window counter problem.

fix by:

function! CheckLeftBuffers()
  if tabpagenr('$') == 1
    let i = 1
    while i <= winnr('$')
      if getbufvar(winbufnr(i), '&buftype') == 'help' ||
          \ getbufvar(winbufnr(i), '&buftype') == 'quickfix' ||
          \ exists('t:NERDTreeBufName') &&
          \   bufname(winbufnr(i)) == t:NERDTreeBufName ||
          \ bufname(winbufnr(i)) == '__Tag_List__'
        let i += 1
      else
        break
      endif
    endwhile
    if i == winnr('$') + 1
      qall
    endif
    unlet i
  endif
endfunction
autocmd BufEnter * call CheckLeftBuffers()

https://yous.be/2014/11/30/automatically-quit-vim-if-actual-files-are-closed

Is Joinable reall joinable?

I found the semantics of joinable thread is really confusing.

if thread start working, the status use “joinable” to indicate the thread is working if joinable is false.

if thread stop working, we wish it exit gracefully, and call join() to tell the system thread has complete it’s destiny.

I just don’t quite understand that: why the author use the word “JOIN”